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