@@ -1495,25 +1495,27 @@ def getfixtureinfo(
14951495
14961496 return FuncFixtureInfo (argnames , initialnames , names_closure , arg2fixturedefs )
14971497
1498- def pytest_plugin_registered (self , plugin : _PluggyPlugin ) -> None :
1499- nodeid = None
1500- try :
1501- p = absolutepath (plugin .__file__ ) # type: ignore[attr-defined]
1502- except AttributeError :
1503- pass
1498+ def pytest_plugin_registered (self , plugin : _PluggyPlugin , plugin_name : str ) -> None :
1499+ # Fixtures defined in conftest plugins are only visible to within the
1500+ # conftest's directory. This is unlike fixtures in non-conftest plugins
1501+ # which have global visibility. So for conftests, construct the base
1502+ # nodeid from the plugin name (which is the conftest path).
1503+ if plugin_name and plugin_name .endswith ("conftest.py" ):
1504+ # Note: we explicitly do *not* use `plugin.__file__` here -- The
1505+ # difference is that plugin_name has the correct capitalization on
1506+ # case-insensitive systems (Windows) and other normalization issues
1507+ # (issue #11816).
1508+ conftestpath = absolutepath (plugin_name )
1509+ try :
1510+ nodeid = str (conftestpath .parent .relative_to (self .config .rootpath ))
1511+ except ValueError :
1512+ nodeid = ""
1513+ if nodeid == "." :
1514+ nodeid = ""
1515+ if os .sep != nodes .SEP :
1516+ nodeid = nodeid .replace (os .sep , nodes .SEP )
15041517 else :
1505- # Construct the base nodeid which is later used to check
1506- # what fixtures are visible for particular tests (as denoted
1507- # by their test id).
1508- if p .name == "conftest.py" :
1509- try :
1510- nodeid = str (p .parent .relative_to (self .config .rootpath ))
1511- except ValueError :
1512- nodeid = ""
1513- if nodeid == "." :
1514- nodeid = ""
1515- if os .sep != nodes .SEP :
1516- nodeid = nodeid .replace (os .sep , nodes .SEP )
1518+ nodeid = None
15171519
15181520 self .parsefactories (plugin , nodeid )
15191521
0 commit comments