@@ -589,7 +589,8 @@ def _set_initial_conftests(
589589 )
590590 self ._noconftest = noconftest
591591 self ._using_pyargs = pyargs
592- foundanchor = False
592+
593+ anchors = []
593594 for initial_path in args :
594595 path = str (initial_path )
595596 # remove node-id syntax
@@ -601,16 +602,18 @@ def _set_initial_conftests(
601602 # Ensure we do not break if what appears to be an anchor
602603 # is in fact a very long option (#10169, #11394).
603604 if safe_exists (anchor ):
604- self ._try_load_conftest (
605- anchor ,
606- importmode ,
607- rootpath ,
608- consider_namespace_packages = consider_namespace_packages ,
609- )
610- foundanchor = True
611- if not foundanchor :
612- self ._try_load_conftest (
613- invocation_dir ,
605+ anchors .append (anchor )
606+ # Let's also consider test* subdirs.
607+ if anchor .is_dir ():
608+ for x in anchor .glob ("test*" ):
609+ if x .is_dir ():
610+ anchors .append (x )
611+ if not anchors :
612+ anchors = [invocation_dir ]
613+
614+ for anchor in anchors :
615+ self ._loadconftestmodules (
616+ anchor ,
614617 importmode ,
615618 rootpath ,
616619 consider_namespace_packages = consider_namespace_packages ,
@@ -631,31 +634,6 @@ def _is_in_confcutdir(self, path: pathlib.Path) -> bool:
631634 # (see #9767 for a regression where the logic was inverted).
632635 return path not in self ._confcutdir .parents
633636
634- def _try_load_conftest (
635- self ,
636- anchor : pathlib .Path ,
637- importmode : str | ImportMode ,
638- rootpath : pathlib .Path ,
639- * ,
640- consider_namespace_packages : bool ,
641- ) -> None :
642- self ._loadconftestmodules (
643- anchor ,
644- importmode ,
645- rootpath ,
646- consider_namespace_packages = consider_namespace_packages ,
647- )
648- # let's also consider test* subdirs
649- if anchor .is_dir ():
650- for x in anchor .glob ("test*" ):
651- if x .is_dir ():
652- self ._loadconftestmodules (
653- x ,
654- importmode ,
655- rootpath ,
656- consider_namespace_packages = consider_namespace_packages ,
657- )
658-
659637 def _loadconftestmodules (
660638 self ,
661639 path : pathlib .Path ,
0 commit comments