Skip to content

Commit

Permalink
fixtures: avoid slow pm.get_name(plugin) call by using the new `plu…
Browse files Browse the repository at this point in the history
…gin_name` hook parameter
  • Loading branch information
bluetech committed Jan 17, 2024
1 parent 0f5ecd8 commit 9ea2e0a
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,27 +1483,27 @@ def getfixtureinfo(

return FuncFixtureInfo(argnames, initialnames, names_closure, arg2fixturedefs)

def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
nodeid = None
plugin_name = self.config.pluginmanager.get_name(plugin)

# Construct the base nodeid which is later used to check
# what fixtures are visible for particular tests (as denoted
# by their test id).
def pytest_plugin_registered(self, plugin: _PluggyPlugin, plugin_name: str) -> None:
# Fixtures defined in conftest plugins are only visible to within the
# conftest's directory. This is unlike fixtures in non-conftest plugins
# which have global visibility. So for conftests, construct the base
# nodeid from the plugin name (which is the conftest path).
if plugin_name and plugin_name.endswith("conftest.py"):
# The plugin name is assumed to be equal to plugin.__file__
# for conftest plugins. The difference is that plugin_name
# has the correct capitalization on capital-insensitive
# systems (Windows).
p = absolutepath(plugin_name)
# Note: we explicitly do *not* use `plugin.__file__` here -- The
# difference is that plugin_name has the correct capitalization on
# case-insensitive systems (Windows) and other normalization issues
# (issue #11816).
conftestpath = absolutepath(plugin_name)
try:
nodeid = str(p.parent.relative_to(self.config.rootpath))
nodeid = str(conftestpath.parent.relative_to(self.config.rootpath))
except ValueError:
nodeid = ""
if nodeid == ".":
nodeid = ""
if os.sep != nodes.SEP:
nodeid = nodeid.replace(os.sep, nodes.SEP)

Check warning on line 1504 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L1504

Added line #L1504 was not covered by tests
else:
nodeid = None

self.parsefactories(plugin, nodeid)

Expand Down

0 comments on commit 9ea2e0a

Please sign in to comment.