@@ -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,14 @@ 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+ # 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 :
556566 self ._try_load_conftest (anchor , namespace .importmode , rootpath )
557567 foundanchor = True
558568 if not foundanchor :
@@ -1131,7 +1141,9 @@ def _processopt(self, opt: "Argument") -> None:
11311141 @hookimpl (trylast = True )
11321142 def pytest_load_initial_conftests (self , early_config : "Config" ) -> None :
11331143 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" ),
11351147 )
11361148
11371149 def _initini (self , args : Sequence [str ]) -> None :
0 commit comments