@@ -526,7 +526,10 @@ def pytest_configure(self, config: "Config") -> None:
526
526
# Internal API for local conftest plugin handling.
527
527
#
528
528
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 ],
530
533
) -> None :
531
534
"""Load initial conftest files given a preparsed "namespace".
532
535
@@ -543,7 +546,7 @@ def _set_initial_conftests(
543
546
)
544
547
self ._noconftest = namespace .noconftest
545
548
self ._using_pyargs = namespace .pyargs
546
- testpaths = namespace .file_or_dir
549
+ testpaths = namespace .file_or_dir + testpaths_ini
547
550
foundanchor = False
548
551
for testpath in testpaths :
549
552
path = str (testpath )
@@ -552,7 +555,20 @@ def _set_initial_conftests(
552
555
if i != - 1 :
553
556
path = path [:i ]
554
557
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.
556
572
self ._try_load_conftest (anchor , namespace .importmode , rootpath )
557
573
foundanchor = True
558
574
if not foundanchor :
@@ -1131,7 +1147,9 @@ def _processopt(self, opt: "Argument") -> None:
1131
1147
@hookimpl (trylast = True )
1132
1148
def pytest_load_initial_conftests (self , early_config : "Config" ) -> None :
1133
1149
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" ),
1135
1153
)
1136
1154
1137
1155
def _initini (self , args : Sequence [str ]) -> None :
0 commit comments