Skip to content

Commit 157f875

Browse files
committed
Optimize/revisit determine_setup
1 parent b131214 commit 157f875

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/_pytest/config/findpaths.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,28 +121,34 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None):
121121
break
122122
except KeyError:
123123
inicfg = None
124-
rootdir = get_common_ancestor(dirs)
124+
if rootdir_cmd_arg is None:
125+
rootdir = get_common_ancestor(dirs)
125126
else:
126127
ancestor = get_common_ancestor(dirs)
127128
rootdir, inifile, inicfg = getcfg([ancestor], config=config)
128-
if rootdir is None:
129-
for rootdir in ancestor.parts(reverse=True):
130-
if rootdir.join("setup.py").exists():
129+
if rootdir is None and rootdir_cmd_arg is None:
130+
for possible_rootdir in ancestor.parts(reverse=True):
131+
if possible_rootdir.join("setup.py").exists():
132+
rootdir = possible_rootdir
131133
break
132134
else:
133-
rootdir, inifile, inicfg = getcfg(dirs, config=config)
135+
if dirs != [ancestor]:
136+
rootdir, inifile, inicfg = getcfg(dirs, config=config)
134137
if rootdir is None:
135-
rootdir = get_common_ancestor([py.path.local(), ancestor])
138+
if config is not None:
139+
cwd = config.invocation_dir
140+
else:
141+
cwd = py.path.local()
142+
rootdir = get_common_ancestor([cwd, ancestor])
136143
is_fs_root = os.path.splitdrive(str(rootdir))[1] == "/"
137144
if is_fs_root:
138145
rootdir = ancestor
139146
if rootdir_cmd_arg:
140-
rootdir_abs_path = py.path.local(os.path.expandvars(rootdir_cmd_arg))
141-
if not os.path.isdir(str(rootdir_abs_path)):
147+
rootdir = py.path.local(os.path.expandvars(rootdir_cmd_arg))
148+
if not rootdir.isdir():
142149
raise UsageError(
143150
"Directory '{}' not found. Check your '--rootdir' option.".format(
144-
rootdir_abs_path
151+
rootdir
145152
)
146153
)
147-
rootdir = rootdir_abs_path
148154
return rootdir, inifile, inicfg or {}

0 commit comments

Comments
 (0)