From 7f3ba3bf8fa314bfbf76785d6bdca05b718ea08b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 14 Mar 2021 20:27:51 -0400 Subject: [PATCH] Simply construct a CheckdocsItem if any Python project file is found. --- pytest_checkdocs/__init__.py | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/pytest_checkdocs/__init__.py b/pytest_checkdocs/__init__.py index 3162319..7bc5244 100644 --- a/pytest_checkdocs/__init__.py +++ b/pytest_checkdocs/__init__.py @@ -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): @@ -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)}"