@@ -526,7 +526,10 @@ def pytest_configure(self, config: "Config") -> None:
526526 # Internal API for local conftest plugin handling.
527527 #
528528 def _set_initial_conftests (
529- self , namespace : argparse .Namespace , rootpath : Path
529+ self ,
530+ namespace : argparse .Namespace ,
531+ rootpath : Path ,
532+ testpaths_ini : Sequence [str ],
530533 ) -> None :
531534 """Load initial conftest files given a preparsed "namespace".
532535
@@ -543,7 +546,7 @@ def _set_initial_conftests(
543546 )
544547 self ._noconftest = namespace .noconftest
545548 self ._using_pyargs = namespace .pyargs
546- testpaths = namespace .file_or_dir
549+ testpaths = namespace .file_or_dir + testpaths_ini
547550 foundanchor = False
548551 for testpath in testpaths :
549552 path = str (testpath )
@@ -552,7 +555,20 @@ def _set_initial_conftests(
552555 if i != - 1 :
553556 path = path [:i ]
554557 anchor = absolutepath (current / path )
555- if anchor .exists (): # we found some file object
558+
559+ # On Python 3.7 on Windows, anchor.exists() might raise
560+ # if the anchor contains glob characters (for example "*//tests"), specially
561+ # in the case of the 'testpaths' ini option.
562+ # Using an explicit version check to remove this code later once
563+ # Python 3.7 is dropped.
564+ if sys .version_info [:2 ] == (3 , 7 ):
565+ try :
566+ anchor_exists = anchor .exists ()
567+ except OSError : # pragma: no cover
568+ anchor_exists = False
569+ else :
570+ anchor_exists = anchor .exists ()
571+ if anchor_exists : # We found some file object.
556572 self ._try_load_conftest (anchor , namespace .importmode , rootpath )
557573 foundanchor = True
558574 if not foundanchor :
@@ -1131,7 +1147,9 @@ def _processopt(self, opt: "Argument") -> None:
11311147 @hookimpl (trylast = True )
11321148 def pytest_load_initial_conftests (self , early_config : "Config" ) -> None :
11331149 self .pluginmanager ._set_initial_conftests (
1134- early_config .known_args_namespace , rootpath = early_config .rootpath
1150+ early_config .known_args_namespace ,
1151+ rootpath = early_config .rootpath ,
1152+ testpaths_ini = self .getini ("testpaths" ),
11351153 )
11361154
11371155 def _initini (self , args : Sequence [str ]) -> None :
0 commit comments