Skip to content

Commit 13e2b00

Browse files
committed
config: don't pass the entire Config to determine_setup()
Seems better to make the function a bit more pure, and avoids the circular import.
1 parent 4e42421 commit 13e2b00

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/_pytest/config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def _initini(self, args: Sequence[str]) -> None:
11701170
ns.inifilename,
11711171
ns.file_or_dir + unknown_args,
11721172
rootdir_cmd_arg=ns.rootdir or None,
1173-
config=self,
1173+
invocation_dir=self.invocation_params.dir,
11741174
)
11751175
self._rootpath = rootpath
11761176
self._inipath = inipath

src/_pytest/config/findpaths.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Optional
88
from typing import Sequence
99
from typing import Tuple
10-
from typing import TYPE_CHECKING
1110
from typing import Union
1211

1312
import iniconfig
@@ -17,9 +16,6 @@
1716
from _pytest.pathlib import absolutepath
1817
from _pytest.pathlib import commonpath
1918

20-
if TYPE_CHECKING:
21-
from . import Config
22-
2319

2420
def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
2521
"""Parse the given generic '.ini' file using legacy IniConfig parser, returning
@@ -176,8 +172,21 @@ def determine_setup(
176172
inifile: Optional[str],
177173
args: Sequence[str],
178174
rootdir_cmd_arg: Optional[str] = None,
179-
config: Optional["Config"] = None,
175+
invocation_dir: Optional[Path] = None,
180176
) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]:
177+
"""Determine the rootdir, inifile and ini configuration values from the
178+
command line arguments.
179+
180+
:param inifile:
181+
The `--inifile` command line argument, if given.
182+
:param args:
183+
The free command line arguments.
184+
:param rootdir_cmd_arg:
185+
The `--rootdir` command line argument, if given.
186+
:param invocation_dir:
187+
The working directory when pytest was invoked, if known.
188+
If not known, the current working directory is used.
189+
"""
181190
rootdir = None
182191
dirs = get_dirs_from_args(args)
183192
if inifile:
@@ -198,8 +207,8 @@ def determine_setup(
198207
if dirs != [ancestor]:
199208
rootdir, inipath, inicfg = locate_config(dirs)
200209
if rootdir is None:
201-
if config is not None:
202-
cwd = config.invocation_params.dir
210+
if invocation_dir is not None:
211+
cwd = invocation_dir
203212
else:
204213
cwd = Path.cwd()
205214
rootdir = get_common_ancestor([cwd, ancestor])

0 commit comments

Comments
 (0)