Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 14 additions & 36 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ def _set_initial_conftests(
)
self._noconftest = noconftest
self._using_pyargs = pyargs
foundanchor = False

anchors = []
for initial_path in args:
path = str(initial_path)
# remove node-id syntax
Expand All @@ -601,16 +602,18 @@ def _set_initial_conftests(
# Ensure we do not break if what appears to be an anchor
# is in fact a very long option (#10169, #11394).
if safe_exists(anchor):
self._try_load_conftest(
anchor,
importmode,
rootpath,
consider_namespace_packages=consider_namespace_packages,
)
foundanchor = True
if not foundanchor:
self._try_load_conftest(
invocation_dir,
anchors.append(anchor)
# Let's also consider test* subdirs.
if anchor.is_dir():
for x in anchor.glob("test*"):
if x.is_dir():
anchors.append(x)
if not anchors:
anchors = [invocation_dir]

for anchor in anchors:
self._loadconftestmodules(
anchor,
importmode,
rootpath,
consider_namespace_packages=consider_namespace_packages,
Expand All @@ -631,31 +634,6 @@ def _is_in_confcutdir(self, path: pathlib.Path) -> bool:
# (see #9767 for a regression where the logic was inverted).
return path not in self._confcutdir.parents

def _try_load_conftest(
self,
anchor: pathlib.Path,
importmode: str | ImportMode,
rootpath: pathlib.Path,
*,
consider_namespace_packages: bool,
) -> None:
self._loadconftestmodules(
anchor,
importmode,
rootpath,
consider_namespace_packages=consider_namespace_packages,
)
# let's also consider test* subdirs
if anchor.is_dir():
for x in anchor.glob("test*"):
if x.is_dir():
self._loadconftestmodules(
x,
importmode,
rootpath,
consider_namespace_packages=consider_namespace_packages,
)

def _loadconftestmodules(
self,
path: pathlib.Path,
Expand Down
Loading