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.
This commit is contained in:
Ran Benita 2023-07-23 14:10:26 +03:00
parent 4e42421ebf
commit 13e2b00258
2 changed files with 17 additions and 8 deletions

View File

@ -1170,7 +1170,7 @@ class Config:
ns.inifilename,
ns.file_or_dir + unknown_args,
rootdir_cmd_arg=ns.rootdir or None,
config=self,
invocation_dir=self.invocation_params.dir,
)
self._rootpath = rootpath
self._inipath = inipath

View File

@ -7,7 +7,6 @@ from typing import List
from typing import Optional
from typing import Sequence
from typing import Tuple
from typing import TYPE_CHECKING
from typing import Union
import iniconfig
@ -17,9 +16,6 @@ from _pytest.outcomes import fail
from _pytest.pathlib import absolutepath
from _pytest.pathlib import commonpath
if TYPE_CHECKING:
from . import Config
def _parse_ini_config(path: Path) -> iniconfig.IniConfig:
"""Parse the given generic '.ini' file using legacy IniConfig parser, returning
@ -176,8 +172,21 @@ def determine_setup(
inifile: Optional[str],
args: Sequence[str],
rootdir_cmd_arg: Optional[str] = None,
config: Optional["Config"] = None,
invocation_dir: Optional[Path] = None,
) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]:
"""Determine the rootdir, inifile and ini configuration values from the
command line arguments.
:param inifile:
The `--inifile` command line argument, if given.
:param args:
The free command line arguments.
:param rootdir_cmd_arg:
The `--rootdir` command line argument, if given.
:param invocation_dir:
The working directory when pytest was invoked, if known.
If not known, the current working directory is used.
"""
rootdir = None
dirs = get_dirs_from_args(args)
if inifile:
@ -198,8 +207,8 @@ def determine_setup(
if dirs != [ancestor]:
rootdir, inipath, inicfg = locate_config(dirs)
if rootdir is None:
if config is not None:
cwd = config.invocation_params.dir
if invocation_dir is not None:
cwd = invocation_dir
else:
cwd = Path.cwd()
rootdir = get_common_ancestor([cwd, ancestor])