Skip to content

Commit 9ea2e0a

Browse files
committed
fixtures: avoid slow pm.get_name(plugin) call by using the new plugin_name hook parameter
1 parent 0f5ecd8 commit 9ea2e0a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/_pytest/fixtures.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,27 +1483,27 @@ def getfixtureinfo(
14831483

14841484
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)
14851485

1486-
def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
1487-
nodeid = None
1488-
plugin_name = self.config.pluginmanager.get_name(plugin)
1489-
1490-
# Construct the base nodeid which is later used to check
1491-
# what fixtures are visible for particular tests (as denoted
1492-
# by their test id).
1486+
def pytest_plugin_registered(self, plugin: _PluggyPlugin, plugin_name: str) -> None:
1487+
# Fixtures defined in conftest plugins are only visible to within the
1488+
# conftest's directory. This is unlike fixtures in non-conftest plugins
1489+
# which have global visibility. So for conftests, construct the base
1490+
# nodeid from the plugin name (which is the conftest path).
14931491
if plugin_name and plugin_name.endswith("conftest.py"):
1494-
# The plugin name is assumed to be equal to plugin.__file__
1495-
# for conftest plugins. The difference is that plugin_name
1496-
# has the correct capitalization on capital-insensitive
1497-
# systems (Windows).
1498-
p = absolutepath(plugin_name)
1492+
# Note: we explicitly do *not* use `plugin.__file__` here -- The
1493+
# difference is that plugin_name has the correct capitalization on
1494+
# case-insensitive systems (Windows) and other normalization issues
1495+
# (issue #11816).
1496+
conftestpath = absolutepath(plugin_name)
14991497
try:
1500-
nodeid = str(p.parent.relative_to(self.config.rootpath))
1498+
nodeid = str(conftestpath.parent.relative_to(self.config.rootpath))
15011499
except ValueError:
15021500
nodeid = ""
15031501
if nodeid == ".":
15041502
nodeid = ""
15051503
if os.sep != nodes.SEP:
15061504
nodeid = nodeid.replace(os.sep, nodes.SEP)
1505+
else:
1506+
nodeid = None
15071507

15081508
self.parsefactories(plugin, nodeid)
15091509

0 commit comments

Comments
 (0)