fixtures: avoid slow `pm.get_name(plugin)` call by using the new `plugin_name` hook parameter
This commit is contained in:
parent
0f5ecd83c4
commit
9ea2e0a79f
|
@ -1483,27 +1483,27 @@ class FixtureManager:
|
||||||
|
|
||||||
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)
|
return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)
|
||||||
|
|
||||||
def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
|
def pytest_plugin_registered(self, plugin: _PluggyPlugin, plugin_name: str) -> None:
|
||||||
nodeid = None
|
# Fixtures defined in conftest plugins are only visible to within the
|
||||||
plugin_name = self.config.pluginmanager.get_name(plugin)
|
# conftest's directory. This is unlike fixtures in non-conftest plugins
|
||||||
|
# which have global visibility. So for conftests, construct the base
|
||||||
# Construct the base nodeid which is later used to check
|
# nodeid from the plugin name (which is the conftest path).
|
||||||
# what fixtures are visible for particular tests (as denoted
|
|
||||||
# by their test id).
|
|
||||||
if plugin_name and plugin_name.endswith("conftest.py"):
|
if plugin_name and plugin_name.endswith("conftest.py"):
|
||||||
# The plugin name is assumed to be equal to plugin.__file__
|
# Note: we explicitly do *not* use `plugin.__file__` here -- The
|
||||||
# for conftest plugins. The difference is that plugin_name
|
# difference is that plugin_name has the correct capitalization on
|
||||||
# has the correct capitalization on capital-insensitive
|
# case-insensitive systems (Windows) and other normalization issues
|
||||||
# systems (Windows).
|
# (issue #11816).
|
||||||
p = absolutepath(plugin_name)
|
conftestpath = absolutepath(plugin_name)
|
||||||
try:
|
try:
|
||||||
nodeid = str(p.parent.relative_to(self.config.rootpath))
|
nodeid = str(conftestpath.parent.relative_to(self.config.rootpath))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
nodeid = ""
|
nodeid = ""
|
||||||
if nodeid == ".":
|
if nodeid == ".":
|
||||||
nodeid = ""
|
nodeid = ""
|
||||||
if os.sep != nodes.SEP:
|
if os.sep != nodes.SEP:
|
||||||
nodeid = nodeid.replace(os.sep, nodes.SEP)
|
nodeid = nodeid.replace(os.sep, nodes.SEP)
|
||||||
|
else:
|
||||||
|
nodeid = None
|
||||||
|
|
||||||
self.parsefactories(plugin, nodeid)
|
self.parsefactories(plugin, nodeid)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue