Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simply construct a CheckdocsItem if any Python project file is found. #9

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions pytest_checkdocs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from jaraco.functools import pass_none


project_files = 'setup.py', 'setup.cfg', 'pyproject.toml'


def pytest_collect_file(path, parent):
"""Filter files down to which ones should be checked."""
return (
CheckdocsItem.from_parent(parent, fspath=path)
if path.basename == 'setup.py'
else None
)
if path.basename not in project_files:
return
return CheckdocsItem.from_parent(parent, name='project')


class Description(str):
Expand All @@ -37,23 +37,7 @@ def repair_field(raw):
return textwrap.dedent(' ' * 8 + raw)


class CheckdocsItem(pytest.Item, pytest.File):
def __init__(self, fspath, parent):
# ugly hack to add support for fspath parameter
# Ref pytest-dev/pytest#6928
super().__init__(fspath, parent)

@classmethod
def from_parent(cls, parent, fspath):
"""
Compatibility shim to support
"""
try:
return super().from_parent(parent, fspath=fspath)
except AttributeError:
# pytest < 5.4
return cls(fspath, parent)

class CheckdocsItem(pytest.Item):
jaraco marked this conversation as resolved.
Show resolved Hide resolved
def runtest(self):
desc = self.get_long_description()
method_name = f"run_{re.sub('[-/]', '_', desc.content_type)}"
Expand Down