Skip to content

Commit 161bc48

Browse files
committed
config: get rid of _conftestpath2mod
It duplicates what PluginManager already knows, and no longer needed now that symlinks are not resolved (see previous commit).
1 parent 0ef8823 commit 161bc48

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

src/_pytest/config/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Command line options, ini-file and conftest.py processing."""
22
import argparse
33
import collections.abc
4-
import contextlib
54
import copy
65
import enum
76
import inspect
@@ -353,8 +352,6 @@ def __init__(self) -> None:
353352
# This includes the directory's own conftest modules as well
354353
# as those of its parent directories.
355354
self._dirpath2confmods: Dict[Path, List[types.ModuleType]] = {}
356-
# The conftest module of a conftest path.
357-
self._conftestpath2mod: Dict[Path, types.ModuleType] = {}
358355
# Cutoff directory above which conftests are no longer discovered.
359356
self._confcutdir: Optional[Path] = None
360357
# If set, conftest loading is skipped.
@@ -592,8 +589,9 @@ def _rget_with_confmod(
592589
def _importconftest(
593590
self, conftestpath: Path, importmode: Union[str, ImportMode], rootpath: Path
594591
) -> types.ModuleType:
595-
with contextlib.suppress(KeyError):
596-
return self._conftestpath2mod[conftestpath]
592+
existing = self.get_plugin(str(conftestpath))
593+
if existing is not None:
594+
return cast(types.ModuleType, existing)
597595

598596
pkgpath = resolve_package_path(conftestpath)
599597
if pkgpath is None:
@@ -609,7 +607,6 @@ def _importconftest(
609607
self._check_non_top_pytest_plugins(mod, conftestpath)
610608

611609
self._conftest_plugins.add(mod)
612-
self._conftestpath2mod[conftestpath] = mod
613610
dirpath = conftestpath.parent
614611
if dirpath in self._dirpath2confmods:
615612
for path, mods in self._dirpath2confmods.items():

testing/test_conftest.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,9 @@ def test_issue151_load_all_conftests(pytester: Pytester) -> None:
146146
p = pytester.mkdir(name)
147147
p.joinpath("conftest.py").touch()
148148

149-
conftest = PytestPluginManager()
150-
conftest_setinitial(conftest, names)
151-
d = list(conftest._conftestpath2mod.values())
152-
assert len(d) == len(names)
149+
pm = PytestPluginManager()
150+
conftest_setinitial(pm, names)
151+
assert len(set(pm.get_plugins()) - {pm}) == len(names)
153152

154153

155154
def test_conftest_global_import(pytester: Pytester) -> None:
@@ -192,7 +191,7 @@ def test_conftestcutdir(pytester: Pytester) -> None:
192191
conf.parent, importmode="prepend", rootpath=pytester.path
193192
)
194193
assert len(values) == 0
195-
assert Path(conf) not in conftest._conftestpath2mod
194+
assert not conftest.has_plugin(str(conf))
196195
# but we can still import a conftest directly
197196
conftest._importconftest(conf, importmode="prepend", rootpath=pytester.path)
198197
values = conftest._getconftestmodules(
@@ -226,15 +225,15 @@ def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
226225
sub = pytester.mkdir(name)
227226
subconftest = sub.joinpath("conftest.py")
228227
subconftest.touch()
229-
conftest = PytestPluginManager()
230-
conftest_setinitial(conftest, [sub.parent], confcutdir=pytester.path)
228+
pm = PytestPluginManager()
229+
conftest_setinitial(pm, [sub.parent], confcutdir=pytester.path)
231230
key = subconftest.resolve()
232231
if name not in ("whatever", ".dotdir"):
233-
assert key in conftest._conftestpath2mod
234-
assert len(conftest._conftestpath2mod) == 1
232+
assert pm.has_plugin(str(key))
233+
assert len(set(pm.get_plugins()) - {pm}) == 1
235234
else:
236-
assert key not in conftest._conftestpath2mod
237-
assert len(conftest._conftestpath2mod) == 0
235+
assert not pm.has_plugin(str(key))
236+
assert len(set(pm.get_plugins()) - {pm}) == 0
238237

239238

240239
def test_conftest_confcutdir(pytester: Pytester) -> None:

0 commit comments

Comments
 (0)