@@ -541,6 +541,7 @@ def _set_initial_conftests(
541
541
noconftest : bool ,
542
542
rootpath : Path ,
543
543
confcutdir : Optional [Path ],
544
+ invocation_dir : Path ,
544
545
importmode : Union [ImportMode , str ],
545
546
) -> None :
546
547
"""Load initial conftest files given a preparsed "namespace".
@@ -550,8 +551,9 @@ def _set_initial_conftests(
550
551
All builtin and 3rd party plugins will have been loaded, however, so
551
552
common options will not confuse our logic here.
552
553
"""
553
- current = Path .cwd ()
554
- self ._confcutdir = absolutepath (current / confcutdir ) if confcutdir else None
554
+ self ._confcutdir = (
555
+ absolutepath (invocation_dir / confcutdir ) if confcutdir else None
556
+ )
555
557
self ._noconftest = noconftest
556
558
self ._using_pyargs = pyargs
557
559
foundanchor = False
@@ -561,15 +563,15 @@ def _set_initial_conftests(
561
563
i = path .find ("::" )
562
564
if i != - 1 :
563
565
path = path [:i ]
564
- anchor = absolutepath (current / path )
566
+ anchor = absolutepath (invocation_dir / path )
565
567
566
568
# Ensure we do not break if what appears to be an anchor
567
569
# is in fact a very long option (#10169, #11394).
568
570
if safe_exists (anchor ):
569
571
self ._try_load_conftest (anchor , importmode , rootpath )
570
572
foundanchor = True
571
573
if not foundanchor :
572
- self ._try_load_conftest (current , importmode , rootpath )
574
+ self ._try_load_conftest (invocation_dir , importmode , rootpath )
573
575
574
576
def _is_in_confcutdir (self , path : Path ) -> bool :
575
577
"""Whether a path is within the confcutdir.
@@ -1168,6 +1170,7 @@ def pytest_load_initial_conftests(self, early_config: "Config") -> None:
1168
1170
noconftest = early_config .known_args_namespace .noconftest ,
1169
1171
rootpath = early_config .rootpath ,
1170
1172
confcutdir = early_config .known_args_namespace .confcutdir ,
1173
+ invocation_dir = early_config .invocation_params .dir ,
1171
1174
importmode = early_config .known_args_namespace .importmode ,
1172
1175
)
1173
1176
@@ -1261,6 +1264,8 @@ def _decide_args(
1261
1264
"""Decide the args (initial paths/nodeids) to use given the relevant inputs.
1262
1265
1263
1266
:param warn: Whether can issue warnings.
1267
+
1268
+ :returns: The args and the args source. Guaranteed to be non-empty.
1264
1269
"""
1265
1270
if args :
1266
1271
source = Config .ArgsSource .ARGS
0 commit comments