Skip to content

Commit f6a343d

Browse files
committed
🐛 Ignore collection failures in non-tests
This change applies the pre-existing patterns to identify if the files with collection problems are tests. It is then used to eliminate the false-positives of F6401 (cannot-enumerate-pytest-fixtures). As a side effect, this patch also includes precise file paths that may be used to reproduce the problem. Fixes reverbc#20 Fixes reverbc#21 Signed-off-by: Sviatoslav Sydorenko <[email protected]> _Replayed; Source PR: https://github.com/reverbc/pylint-pytest/pull/22_ Additionally, satisfied the https://github.com/pylint-dev/pylint-pytest's `.pre-commit-config.yaml` Signed-off-by: Stavros Ntentos <[email protected]>
1 parent a5c6855 commit f6a343d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

pylint_pytest/checkers/fixture.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class FixtureChecker(BasePytestChecker):
6868
"F6401": (
6969
(
7070
"pylint-pytest plugin cannot enumerate and collect pytest fixtures. "
71-
"Please run `pytest --fixtures --collect-only path/to/current/module.py`"
72-
" and resolve any potential syntax error or package dependency issues"
71+
"Please run `pytest --fixtures --collect-only %s` and resolve "
72+
"any potential syntax error or package dependency issues"
7373
),
7474
"cannot-enumerate-pytest-fixtures",
7575
"Used when pylint-pytest has been unable to enumerate and collect pytest fixtures.",
@@ -143,8 +143,23 @@ def visit_module(self, node):
143143

144144
FixtureChecker._pytest_fixtures = fixture_collector.fixtures
145145

146-
if (ret != pytest.ExitCode.OK or fixture_collector.errors) and is_test_module:
147-
self.add_message("cannot-enumerate-pytest-fixtures", node=node)
146+
legitimate_failure_paths = set(
147+
collection_report.nodeid
148+
for collection_report in fixture_collector.errors
149+
if any(
150+
fnmatch.fnmatch(
151+
Path(collection_report.nodeid).name,
152+
pattern,
153+
)
154+
for pattern in FILE_NAME_PATTERNS
155+
)
156+
)
157+
if (ret != pytest.ExitCode.OK or legitimate_failure_paths) and is_test_module:
158+
self.add_message(
159+
"cannot-enumerate-pytest-fixtures",
160+
args=" ".join(legitimate_failure_paths | {node.file}),
161+
node=node,
162+
)
148163
finally:
149164
# restore output devices
150165
sys.stdout, sys.stderr = stdout, stderr

0 commit comments

Comments
 (0)