@@ -527,9 +527,12 @@ def pytest_configure(self, config: "Config") -> None:
527
527
#
528
528
def _set_initial_conftests (
529
529
self ,
530
- namespace : argparse .Namespace ,
530
+ args : Sequence [Union [str , Path ]],
531
+ pyargs : bool ,
532
+ noconftest : bool ,
531
533
rootpath : Path ,
532
- testpaths_ini : Sequence [str ],
534
+ confcutdir : Optional [Path ],
535
+ importmode : Union [ImportMode , str ],
533
536
) -> None :
534
537
"""Load initial conftest files given a preparsed "namespace".
535
538
@@ -539,17 +542,12 @@ def _set_initial_conftests(
539
542
common options will not confuse our logic here.
540
543
"""
541
544
current = Path .cwd ()
542
- self ._confcutdir = (
543
- absolutepath (current / namespace .confcutdir )
544
- if namespace .confcutdir
545
- else None
546
- )
547
- self ._noconftest = namespace .noconftest
548
- self ._using_pyargs = namespace .pyargs
549
- testpaths = namespace .file_or_dir + testpaths_ini
545
+ self ._confcutdir = absolutepath (current / confcutdir ) if confcutdir else None
546
+ self ._noconftest = noconftest
547
+ self ._using_pyargs = pyargs
550
548
foundanchor = False
551
- for testpath in testpaths :
552
- path = str (testpath )
549
+ for intitial_path in args :
550
+ path = str (intitial_path )
553
551
# remove node-id syntax
554
552
i = path .find ("::" )
555
553
if i != - 1 :
@@ -563,10 +561,10 @@ def _set_initial_conftests(
563
561
except OSError : # pragma: no cover
564
562
anchor_exists = False
565
563
if anchor_exists :
566
- self ._try_load_conftest (anchor , namespace . importmode , rootpath )
564
+ self ._try_load_conftest (anchor , importmode , rootpath )
567
565
foundanchor = True
568
566
if not foundanchor :
569
- self ._try_load_conftest (current , namespace . importmode , rootpath )
567
+ self ._try_load_conftest (current , importmode , rootpath )
570
568
571
569
def _is_in_confcutdir (self , path : Path ) -> bool :
572
570
"""Whether a path is within the confcutdir.
@@ -1140,10 +1138,25 @@ def _processopt(self, opt: "Argument") -> None:
1140
1138
1141
1139
@hookimpl (trylast = True )
1142
1140
def pytest_load_initial_conftests (self , early_config : "Config" ) -> None :
1141
+ # We haven't fully parsed the command line arguments yet, so
1142
+ # early_config.args it not set yet. But we need it for
1143
+ # discovering the initial conftests. So "pre-run" the logic here.
1144
+ # It will be done for real in `parse()`.
1145
+ args , args_source = early_config ._decide_args (
1146
+ args = early_config .known_args_namespace .file_or_dir ,
1147
+ pyargs = early_config .known_args_namespace .pyargs ,
1148
+ testpaths = early_config .getini ("testpaths" ),
1149
+ invocation_dir = early_config .invocation_params .dir ,
1150
+ rootpath = early_config .rootpath ,
1151
+ warn = False ,
1152
+ )
1143
1153
self .pluginmanager ._set_initial_conftests (
1144
- early_config .known_args_namespace ,
1154
+ args = args ,
1155
+ pyargs = early_config .known_args_namespace .pyargs ,
1156
+ noconftest = early_config .known_args_namespace .noconftest ,
1145
1157
rootpath = early_config .rootpath ,
1146
- testpaths_ini = self .getini ("testpaths" ),
1158
+ confcutdir = early_config .known_args_namespace .confcutdir ,
1159
+ importmode = early_config .known_args_namespace .importmode ,
1147
1160
)
1148
1161
1149
1162
def _initini (self , args : Sequence [str ]) -> None :
0 commit comments