-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
My setup is a bit elaborate since I am using pyinstaller
and running pytest
from the bundled executable. Anyway, I can tell from the header that pytest
is using C:\
as a rootdir and generates C:\.pytest_cache
, which I would like to avoid.
By debugging determine_setup
pytest/src/_pytest/config/findpaths.py
Lines 175 to 218 in bc4e70e
def determine_setup( | |
inifile: Optional[str], | |
args: Sequence[str], | |
rootdir_cmd_arg: Optional[str] = None, | |
config: Optional["Config"] = None, | |
) -> Tuple[Path, Optional[Path], Dict[str, Union[str, List[str]]]]: | |
rootdir = None | |
dirs = get_dirs_from_args(args) | |
if inifile: | |
inipath_ = absolutepath(inifile) | |
inipath: Optional[Path] = inipath_ | |
inicfg = load_config_dict_from_file(inipath_) or {} | |
if rootdir_cmd_arg is None: | |
rootdir = inipath_.parent | |
else: | |
ancestor = get_common_ancestor(dirs) | |
rootdir, inipath, inicfg = locate_config([ancestor]) | |
if rootdir is None and rootdir_cmd_arg is None: | |
for possible_rootdir in (ancestor, *ancestor.parents): | |
if (possible_rootdir / "setup.py").is_file(): | |
rootdir = possible_rootdir | |
break | |
else: | |
if dirs != [ancestor]: | |
rootdir, inipath, inicfg = locate_config(dirs) | |
if rootdir is None: | |
if config is not None: | |
cwd = config.invocation_params.dir | |
else: | |
cwd = Path.cwd() | |
rootdir = get_common_ancestor([cwd, ancestor]) | |
is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/" | |
if is_fs_root: | |
rootdir = ancestor | |
if rootdir_cmd_arg: | |
rootdir = absolutepath(os.path.expandvars(rootdir_cmd_arg)) | |
if not rootdir.is_dir(): | |
raise UsageError( | |
"Directory '{}' not found. Check your '--rootdir' option.".format( | |
rootdir | |
) | |
) | |
assert rootdir is not None | |
return rootdir, inipath, inicfg or {} |
I have found that it is being called with the following parameters:
inifile = None
args = ['C:\\Users\\bers\\AppData\\Local\\Temp\\_MEI138802\\project']
rootdir_cmd_arg = None
rootdir = None
config = <_pytest.config.Config object at 0x0000021A33D60490>
I have no relevant config in the app bundle, so the function passes via
pytest/src/_pytest/config/findpaths.py
Lines 205 to 208 in bc4e70e
rootdir = get_common_ancestor([cwd, ancestor]) | |
is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/" | |
if is_fs_root: | |
rootdir = ancestor |
with
cwd = WindowsPath('C:/Code/project')
ancestor = WindowsPath('C:/Users/bers/AppData/Local/Temp/_MEI138802/project')
rootdir = get_common_ancestor([cwd, ancestor])
returns WindowsPath('C:/')
, but the following check returns false
as os.path.splitdrive(str(rootdir))[1]
is "\\"
, not "/"
. As a consequence, rootdir
is not set to ancestor
, but remains at WindowsPath('C:/')
, which I believe is not intended.
TLDR: In
pytest/src/_pytest/config/findpaths.py
Line 206 in bc4e70e
is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/" |
"/"
to os.sep
.