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:
parent
40011b838b
commit
998fee1679
|
@ -578,12 +578,18 @@ class PytestPluginManager(PluginManager):
|
||||||
self._try_load_conftest(invocation_dir, importmode, rootpath)
|
self._try_load_conftest(invocation_dir, importmode, rootpath)
|
||||||
|
|
||||||
def _is_in_confcutdir(self, path: Path) -> bool:
|
def _is_in_confcutdir(self, path: Path) -> bool:
|
||||||
"""Whether a path is within the confcutdir.
|
"""Whether to consider the given path to load conftests from."""
|
||||||
|
|
||||||
When false, should not load conftest.
|
|
||||||
"""
|
|
||||||
if self._confcutdir is None:
|
if self._confcutdir is None:
|
||||||
return True
|
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
|
return path not in self._confcutdir.parents
|
||||||
|
|
||||||
def _try_load_conftest(
|
def _try_load_conftest(
|
||||||
|
@ -609,9 +615,6 @@ class PytestPluginManager(PluginManager):
|
||||||
if directory in self._dirpath2confmods:
|
if directory in self._dirpath2confmods:
|
||||||
return
|
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 = []
|
clist = []
|
||||||
for parent in reversed((directory, *directory.parents)):
|
for parent in reversed((directory, *directory.parents)):
|
||||||
if self._is_in_confcutdir(parent):
|
if self._is_in_confcutdir(parent):
|
||||||
|
|
Loading…
Reference in New Issue