config: get rid of _conftestpath2mod
It duplicates what PluginManager already knows, and no longer needed now that symlinks are not resolved (see previous commit).
This commit is contained in:
parent
0ef882364e
commit
161bc48117
|
@ -1,7 +1,6 @@
|
|||
"""Command line options, ini-file and conftest.py processing."""
|
||||
import argparse
|
||||
import collections.abc
|
||||
import contextlib
|
||||
import copy
|
||||
import enum
|
||||
import inspect
|
||||
|
@ -353,8 +352,6 @@ class PytestPluginManager(PluginManager):
|
|||
# This includes the directory's own conftest modules as well
|
||||
# as those of its parent directories.
|
||||
self._dirpath2confmods: Dict[Path, List[types.ModuleType]] = {}
|
||||
# The conftest module of a conftest path.
|
||||
self._conftestpath2mod: Dict[Path, types.ModuleType] = {}
|
||||
# Cutoff directory above which conftests are no longer discovered.
|
||||
self._confcutdir: Optional[Path] = None
|
||||
# If set, conftest loading is skipped.
|
||||
|
@ -592,8 +589,9 @@ class PytestPluginManager(PluginManager):
|
|||
def _importconftest(
|
||||
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
|
||||
) -> types.ModuleType:
|
||||
with contextlib.suppress(KeyError):
|
||||
return self._conftestpath2mod[conftestpath]
|
||||
existing = self.get_plugin(str(conftestpath))
|
||||
if existing is not None:
|
||||
return cast(types.ModuleType, existing)
|
||||
|
||||
pkgpath = resolve_package_path(conftestpath)
|
||||
if pkgpath is None:
|
||||
|
@ -609,7 +607,6 @@ class PytestPluginManager(PluginManager):
|
|||
self._check_non_top_pytest_plugins(mod, conftestpath)
|
||||
|
||||
self._conftest_plugins.add(mod)
|
||||
self._conftestpath2mod[conftestpath] = mod
|
||||
dirpath = conftestpath.parent
|
||||
if dirpath in self._dirpath2confmods:
|
||||
for path, mods in self._dirpath2confmods.items():
|
||||
|
|
|
@ -146,10 +146,9 @@ def test_issue151_load_all_conftests(pytester: Pytester) -> None:
|
|||
p = pytester.mkdir(name)
|
||||
p.joinpath("conftest.py").touch()
|
||||
|
||||
conftest = PytestPluginManager()
|
||||
conftest_setinitial(conftest, names)
|
||||
d = list(conftest._conftestpath2mod.values())
|
||||
assert len(d) == len(names)
|
||||
pm = PytestPluginManager()
|
||||
conftest_setinitial(pm, names)
|
||||
assert len(set(pm.get_plugins()) - {pm}) == len(names)
|
||||
|
||||
|
||||
def test_conftest_global_import(pytester: Pytester) -> None:
|
||||
|
@ -192,7 +191,7 @@ def test_conftestcutdir(pytester: Pytester) -> None:
|
|||
conf.parent, importmode="prepend", rootpath=pytester.path
|
||||
)
|
||||
assert len(values) == 0
|
||||
assert Path(conf) not in conftest._conftestpath2mod
|
||||
assert not conftest.has_plugin(str(conf))
|
||||
# but we can still import a conftest directly
|
||||
conftest._importconftest(conf, importmode="prepend", rootpath=pytester.path)
|
||||
values = conftest._getconftestmodules(
|
||||
|
@ -226,15 +225,15 @@ def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
|
|||
sub = pytester.mkdir(name)
|
||||
subconftest = sub.joinpath("conftest.py")
|
||||
subconftest.touch()
|
||||
conftest = PytestPluginManager()
|
||||
conftest_setinitial(conftest, [sub.parent], confcutdir=pytester.path)
|
||||
pm = PytestPluginManager()
|
||||
conftest_setinitial(pm, [sub.parent], confcutdir=pytester.path)
|
||||
key = subconftest.resolve()
|
||||
if name not in ("whatever", ".dotdir"):
|
||||
assert key in conftest._conftestpath2mod
|
||||
assert len(conftest._conftestpath2mod) == 1
|
||||
assert pm.has_plugin(str(key))
|
||||
assert len(set(pm.get_plugins()) - {pm}) == 1
|
||||
else:
|
||||
assert key not in conftest._conftestpath2mod
|
||||
assert len(conftest._conftestpath2mod) == 0
|
||||
assert not pm.has_plugin(str(key))
|
||||
assert len(set(pm.get_plugins()) - {pm}) == 0
|
||||
|
||||
|
||||
def test_conftest_confcutdir(pytester: Pytester) -> None:
|
||||
|
|
Loading…
Reference in New Issue