Skip to content

Commit

Permalink
Clarify PytestPluginManager._is_in_confcutdir
Browse files Browse the repository at this point in the history
Follow up to pytest-dev#12006, let's put some comments clarifying `is_in_confcutdir` semantics, as this is not the first time someone misunderstands it.

Also removed an obsolete comment in `_loadconftestmodules`: we already set the `confcutdir` based on `rootdir`/`initfile` if not explicitly given.
  • Loading branch information
nicoddemus committed Feb 18, 2024
1 parent 40011b8 commit b85b386
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/_pytest/config/__init__.py
Expand Up @@ -578,12 +578,18 @@ def _set_initial_conftests(
self._try_load_conftest(invocation_dir, importmode, rootpath)

def _is_in_confcutdir(self, path: Path) -> bool:
"""Whether a path is within the confcutdir.
When false, should not load conftest.
"""
"""Whether consider the given path to load conftests from."""
if self._confcutdir is None:
return True
# The semantics here are literally:
# Do not load a conftest if it is found upwards from confcut dir.
# But this is *not* the same as:
# Load only conftests from confcutdir or below.
# At first glance they might seem the same thing, however we do support use cases where
# we want to load conftests that are not found in confcutdir or below, but are found
# in completely different directory hierarchies like packages installed
# in out-of-source trees.
# (see #9767 for a regression where the logic was inverted).
return path not in self._confcutdir.parents

def _try_load_conftest(
Expand All @@ -609,9 +615,6 @@ def _loadconftestmodules(
if directory in self._dirpath2confmods:
return

# XXX these days we may rather want to use config.rootpath
# and allow users to opt into looking into the rootdir parent
# directories instead of requiring to specify confcutdir.
clist = []
for parent in reversed((directory, *directory.parents)):
if self._is_in_confcutdir(parent):
Expand Down

0 comments on commit b85b386

Please sign in to comment.