From a86b89e1e3f1ee2b33c97863f856634bbb619557 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Wed, 18 Aug 2021 01:24:44 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Ignore=20collection=20failures?= =?UTF-8?q?=20in=20non-tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #21 --- pylint_pytest/checkers/fixture.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pylint_pytest/checkers/fixture.py b/pylint_pytest/checkers/fixture.py index c2a00a0..738abb2 100644 --- a/pylint_pytest/checkers/fixture.py +++ b/pylint_pytest/checkers/fixture.py @@ -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.', @@ -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}), + node=node, + ) finally: # restore output devices sys.stdout, sys.stderr = stdout, stderr