Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

🐛 Ignore collection failures in non-tests #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions pylint_pytest/checkers/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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 @@ -135,8 +135,22 @@ 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}),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that there's a potential duplication from this line: legitimate_failure_paths can contain relative paths, but the node.file is in absolute path. In my env it's throwing out pytest warning with duplicated paths:

sandbox/test_parent.py:1:0: F6401: pylint-pytest plugin cannot enumerate and collect pytest fixtures. Please run `pytest --fixtures --collect-only sandbox/test_parent.py /Users/reverbc/Workspace/pylint-pytest/sandbox/test_parent.py` and resolve any potential syntax error or package dependency issues (cannot-enumerate-pytest-fixtures)

Where the sandbox/test_parent.py and /Users/reverbc/Workspace/pylint-pytest/sandbox/test_parent.py are pointing to the same file.

Can you help to unify the path strings, maybe with str(Path(...).absolute()) for both collection_report.nodeid and node.file?

node=node,
)
finally:
# restore output devices
sys.stdout, sys.stderr = stdout, stderr
Expand Down