@@ -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,14 @@ 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
+ # Ensure we do not break if what appears to be an anchor
560
+ # is in fact a very long option (#10169).
561
+ try :
562
+ anchor_exists = anchor .exists ()
563
+ except OSError : # pragma: no cover
564
+ anchor_exists = False
565
+ if anchor_exists :
556
566
self ._try_load_conftest (anchor , namespace .importmode , rootpath )
557
567
foundanchor = True
558
568
if not foundanchor :
@@ -1131,7 +1141,9 @@ def _processopt(self, opt: "Argument") -> None:
1131
1141
@hookimpl (trylast = True )
1132
1142
def pytest_load_initial_conftests (self , early_config : "Config" ) -> None :
1133
1143
self .pluginmanager ._set_initial_conftests (
1134
- early_config .known_args_namespace , rootpath = early_config .rootpath
1144
+ early_config .known_args_namespace ,
1145
+ rootpath = early_config .rootpath ,
1146
+ testpaths_ini = self .getini ("testpaths" ),
1135
1147
)
1136
1148
1137
1149
def _initini (self , args : Sequence [str ]) -> None :
0 commit comments