Clarify PytestPluginManager._is_in_confcutdir (#12007)

Follow up to #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.

Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
Bruno Oliveira 2024-02-18 17:27:47 -03:00 committed by GitHub
parent 40011b838b
commit 998fee1679
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -578,12 +578,18 @@ class PytestPluginManager(PluginManager):
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 to 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(
@ -609,9 +615,6 @@ class PytestPluginManager(PluginManager):
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):