Skip to content

Commit 0d169d8

Browse files
committed
avoid using __file__ in pytest_plugin_registered as can be wrong on Windows
1 parent 348e6de commit 0d169d8

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/_pytest/fixtures.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -1485,23 +1485,21 @@ def getfixtureinfo(
14851485

14861486
def pytest_plugin_registered(self, plugin: _PluggyPlugin) -> None:
14871487
nodeid = None
1488-
try:
1489-
p = absolutepath(plugin.__file__) # type: ignore[attr-defined]
1490-
except AttributeError:
1491-
pass
1492-
else:
1493-
# Construct the base nodeid which is later used to check
1494-
# what fixtures are visible for particular tests (as denoted
1495-
# by their test id).
1496-
if p.name == "conftest.py":
1497-
try:
1498-
nodeid = str(p.parent.relative_to(self.config.rootpath))
1499-
except ValueError:
1500-
nodeid = ""
1501-
if nodeid == ".":
1502-
nodeid = ""
1503-
if os.sep != nodes.SEP:
1504-
nodeid = nodeid.replace(os.sep, nodes.SEP)
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).
1493+
if plugin_name.endswith("conftest.py"):
1494+
p = absolutepath(plugin_name)
1495+
try:
1496+
nodeid = str(p.parent.relative_to(self.config.rootpath))
1497+
except ValueError:
1498+
nodeid = ""
1499+
if nodeid == ".":
1500+
nodeid = ""
1501+
if os.sep != nodes.SEP:
1502+
nodeid = nodeid.replace(os.sep, nodes.SEP)
15051503

15061504
self.parsefactories(plugin, nodeid)
15071505

0 commit comments

Comments
 (0)