Skip to content

Commit

Permalink
Merge pull request #9 from jaraco/feature/simple-item
Browse files Browse the repository at this point in the history
Simply construct a CheckdocsItem if any Python project file is found.
  • Loading branch information
jaraco authored Mar 28, 2021
2 parents 42a50c4 + 7f3ba3b commit 57e589d
Showing 1 changed file with 7 additions and 23 deletions.
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):
def runtest(self):
desc = self.get_long_description()
method_name = f"run_{re.sub('[-/]', '_', desc.content_type)}"
Expand Down

0 comments on commit 57e589d

Please sign in to comment.