11import os
22import sys
3+ from pathlib import Path
4+ import fnmatch
5+
36import astroid
47import pylint
58from pylint .checkers .variables import VariablesChecker
1417)
1518from . import BasePytestChecker
1619
20+ # TODO: support pytest python_files configuration
21+ FILE_NAME_PATTERNS = ('test_*.py' , '*_test.py' )
22+
1723
1824class FixtureCollector :
1925 fixtures = {}
@@ -55,7 +61,7 @@ class FixtureChecker(BasePytestChecker):
5561 'F6401' : (
5662 (
5763 'pylint-pytest plugin cannot enumerate and collect pytest fixtures. '
58- 'Please run `pytest --fixtures --collect-only` and resolve any potential syntax error or package dependency issues'
64+ 'Please run `pytest --fixtures --collect-only path/to/current/module.py ` and resolve any potential syntax error or package dependency issues'
5965 ),
6066 'cannot-enumerate-pytest-fixtures' ,
6167 'Used when pylint-pytest has been unable to enumerate and collect pytest fixtures.' ,
@@ -98,6 +104,12 @@ def visit_module(self, node):
98104 # storing all invoked fixtures through @pytest.mark.usefixture(...)
99105 FixtureChecker ._invoked_with_usefixtures = set () # Set[str]
100106
107+ is_test_module = False
108+ for pattern in FILE_NAME_PATTERNS :
109+ if fnmatch .fnmatch (Path (node .file ).name , pattern ):
110+ is_test_module = True
111+ break
112+
101113 try :
102114 with open (os .devnull , 'w' ) as devnull :
103115 # suppress any future output from pytest
@@ -123,7 +135,7 @@ def visit_module(self, node):
123135
124136 FixtureChecker ._pytest_fixtures = fixture_collector .fixtures
125137
126- if ret != pytest .ExitCode .OK or fixture_collector .errors :
138+ if ( ret != pytest .ExitCode .OK or fixture_collector .errors ) and is_test_module :
127139 self .add_message ('cannot-enumerate-pytest-fixtures' , node = node )
128140 finally :
129141 # restore output devices
0 commit comments