Skip to content

Commit

Permalink
config: get rid of _conftestpath2mod
Browse files Browse the repository at this point in the history
It duplicates what PluginManager already knows, and no longer needed now
that symlinks are not resolved (see previous commit).
  • Loading branch information
bluetech committed Jan 9, 2022
1 parent f80502e commit 61d0954
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
9 changes: 3 additions & 6 deletions src/_pytest/config/__init__.py
@@ -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
Expand Down Expand Up @@ -353,8 +352,6 @@ def __init__(self) -> None:
# 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.
Expand Down Expand Up @@ -592,8 +589,9 @@ def _rget_with_confmod(
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:
Expand All @@ -609,7 +607,6 @@ def _importconftest(
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():
Expand Down
21 changes: 10 additions & 11 deletions testing/test_conftest.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 61d0954

Please sign in to comment.