Skip to content

Commit

Permalink
avoid using __file__ in pytest_plugin_registered as can be wrong on W…
Browse files Browse the repository at this point in the history
…indows
  • Loading branch information
woutdenolf committed Jan 16, 2024
1 parent 348e6de commit ef99b0e
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,23 +1485,25 @@ def getfixtureinfo(

def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
nodeid = None
try:
p = absolutepath(plugin.__file__) # type: ignore[attr-defined]
except AttributeError:
pass
else:
# Construct the base nodeid which is later used to check
# what fixtures are visible for particular tests (as denoted
# by their test id).
if p.name == "conftest.py":
try:
nodeid = str(p.parent.relative_to(self.config.rootpath))
except ValueError:
nodeid = ""
if nodeid == ".":
nodeid = ""
if os.sep != nodes.SEP:
nodeid = nodeid.replace(os.sep, nodes.SEP)
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).
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)
try:
nodeid = str(p.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 1506 in src/_pytest/fixtures.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/fixtures.py#L1506

Added line #L1506 was not covered by tests

self.parsefactories(plugin, nodeid)

Expand Down

0 comments on commit ef99b0e

Please sign in to comment.