Skip to content

Commit

Permalink
🐛 Ignore collection failures in non-tests
Browse files Browse the repository at this point in the history
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 <wk@sydorenko.org.ua>

_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 <133706+stdedos@users.noreply.github.com>
  • Loading branch information
stdedos committed Oct 23, 2023
1 parent a5c6855 commit f6a343d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions pylint_pytest/checkers/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class FixtureChecker(BasePytestChecker):
"F6401": (
(
"pylint-pytest plugin cannot enumerate and collect pytest fixtures. "
"Please run `pytest --fixtures --collect-only path/to/current/module.py`"
" and resolve any potential syntax error or package dependency issues"
"Please run `pytest --fixtures --collect-only %s` and resolve "
"any potential syntax error or package dependency issues"
),
"cannot-enumerate-pytest-fixtures",
"Used when pylint-pytest has been unable to enumerate and collect pytest fixtures.",
Expand Down Expand Up @@ -143,8 +143,23 @@ def visit_module(self, node):

FixtureChecker._pytest_fixtures = fixture_collector.fixtures

if (ret != pytest.ExitCode.OK or fixture_collector.errors) and is_test_module:
self.add_message("cannot-enumerate-pytest-fixtures", node=node)
legitimate_failure_paths = set(
collection_report.nodeid
for collection_report in fixture_collector.errors
if any(
fnmatch.fnmatch(
Path(collection_report.nodeid).name,
pattern,
)
for pattern in FILE_NAME_PATTERNS
)
)
if (ret != pytest.ExitCode.OK or legitimate_failure_paths) and is_test_module:
self.add_message(
"cannot-enumerate-pytest-fixtures",
args=" ".join(legitimate_failure_paths | {node.file}),
node=node,
)
finally:
# restore output devices
sys.stdout, sys.stderr = stdout, stderr
Expand Down

0 comments on commit f6a343d

Please sign in to comment.