config: clarify a bit of code in `_importconftest`

This commit is contained in:
Ran Benita 2023-12-25 19:40:40 +02:00
parent 368fa2c03e
commit 35a3863b15
1 changed files with 8 additions and 8 deletions

View File

@ -638,9 +638,16 @@ class PytestPluginManager(PluginManager):
if existing is not None:
return cast(types.ModuleType, existing)
# conftest.py files there are not in a Python package all have module
# name "conftest", and thus conflict with each other. Clear the existing
# before loading the new one, otherwise the existing one will be
# returned from the module cache.
pkgpath = resolve_package_path(conftestpath)
if pkgpath is None:
_ensure_removed_sysmodule(conftestpath.stem)
try:
del sys.modules[conftestpath.stem]
except KeyError:
pass
try:
mod = import_path(conftestpath, mode=importmode, root=rootpath)
@ -818,13 +825,6 @@ def _get_plugin_specs_as_list(
)
def _ensure_removed_sysmodule(modname: str) -> None:
try:
del sys.modules[modname]
except KeyError:
pass
class Notset:
def __repr__(self):
return "<NOTSET>"