File tree Expand file tree Collapse file tree 4 files changed +22
-5
lines changed Expand file tree Collapse file tree 4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change
1
+ Fix handling of ``collect_ignore `` via parent ``conftest.py ``.
Original file line number Diff line number Diff line change @@ -607,6 +607,7 @@ def filter_(f):
607
607
yield y
608
608
609
609
def _collectfile (self , path , handle_dupes = True ):
610
+ assert path .isfile ()
610
611
ihook = self .gethookproxy (path )
611
612
if not self .isinitpath (path ):
612
613
if ihook .pytest_ignore_collect (path = path , config = self .config ):
Original file line number Diff line number Diff line change @@ -599,6 +599,7 @@ def gethookproxy(self, fspath):
599
599
return proxy
600
600
601
601
def _collectfile (self , path , handle_dupes = True ):
602
+ assert path .isfile ()
602
603
ihook = self .gethookproxy (path )
603
604
if not self .isinitpath (path ):
604
605
if ihook .pytest_ignore_collect (path = path , config = self .config ):
@@ -642,11 +643,12 @@ def collect(self):
642
643
):
643
644
continue
644
645
645
- if path .isdir () and path .join ("__init__.py" ).check (file = 1 ):
646
- pkg_prefixes .add (path )
647
-
648
- for x in self ._collectfile (path ):
649
- yield x
646
+ if path .isdir ():
647
+ if path .join ("__init__.py" ).check (file = 1 ):
648
+ pkg_prefixes .add (path )
649
+ else :
650
+ for x in self ._collectfile (path ):
651
+ yield x
650
652
651
653
652
654
def _get_xunit_setup_teardown (holder , attr_name , param_obj = None ):
Original file line number Diff line number Diff line change @@ -1144,3 +1144,16 @@ def test_nodeid(request):
1144
1144
]
1145
1145
)
1146
1146
assert result .ret == 0
1147
+
1148
+
1149
+ def test_collectignore_via_conftest (testdir , monkeypatch ):
1150
+ """collect_ignore in parent conftest skips importing child (issue #4592)."""
1151
+ tests = testdir .mkpydir ("tests" )
1152
+ tests .ensure ("conftest.py" ).write ("collect_ignore = ['ignore_me']" )
1153
+
1154
+ ignore_me = tests .mkdir ("ignore_me" )
1155
+ ignore_me .ensure ("__init__.py" )
1156
+ ignore_me .ensure ("conftest.py" ).write ("assert 0, 'should_not_be_called'" )
1157
+
1158
+ result = testdir .runpytest ()
1159
+ assert result .ret == EXIT_NOTESTSCOLLECTED
You can’t perform that action at this time.
0 commit comments