Skip to content

Commit 4b28ef5

Browse files
webknjazstdedos
authored andcommitted
🐛 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: Stavros Ntentos <[email protected]>
1 parent 6267638 commit 4b28ef5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pylint_pytest/checkers/fixture.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class FixtureChecker(BasePytestChecker):
6161
'F6401': (
6262
(
6363
'pylint-pytest plugin cannot enumerate and collect pytest fixtures. '
64-
'Please run `pytest --fixtures --collect-only path/to/current/module.py` and resolve any potential syntax error or package dependency issues'
64+
'Please run `pytest --fixtures --collect-only %s` and resolve any potential syntax error or package dependency issues'
6565
),
6666
'cannot-enumerate-pytest-fixtures',
6767
'Used when pylint-pytest has been unable to enumerate and collect pytest fixtures.',
@@ -135,8 +135,22 @@ def visit_module(self, node):
135135

136136
FixtureChecker._pytest_fixtures = fixture_collector.fixtures
137137

138-
if (ret != pytest.ExitCode.OK or fixture_collector.errors) and is_test_module:
139-
self.add_message('cannot-enumerate-pytest-fixtures', node=node)
138+
legitimate_failure_paths = set(
139+
collection_report.nodeid
140+
for collection_report in fixture_collector.errors
141+
if any(
142+
fnmatch.fnmatch(
143+
Path(collection_report.nodeid).name, pattern,
144+
)
145+
for pattern in FILE_NAME_PATTERNS
146+
)
147+
)
148+
if (ret != pytest.ExitCode.OK or legitimate_failure_paths) and is_test_module:
149+
self.add_message(
150+
'cannot-enumerate-pytest-fixtures',
151+
args=' '.join(legitimate_failure_paths | {node.file}),
152+
node=node,
153+
)
140154
finally:
141155
# restore output devices
142156
sys.stdout, sys.stderr = stdout, stderr

0 commit comments

Comments
 (0)