@@ -620,6 +620,24 @@ def _patched_collect():
620
620
collector .obj .__pytest_asyncio_scoped_event_loop = scoped_event_loop
621
621
return collector .__original_collect ()
622
622
623
+ collector .__original_collect = collector .collect
624
+ collector .collect = _patched_collect
625
+ elif type (collector ) is Package :
626
+
627
+ def _patched_collect ():
628
+ # When collector is a package, collector.obj is the package's __init__.py.
629
+ # pytest doesn't seem to collect fixtures in __init__.py.
630
+ # Using parsefactories to collect fixtures in __init__.py their baseid will
631
+ # end with "__init__.py", thus limiting the scope of the fixture to the
632
+ # init module. Therefore, we tell the pluginmanager explicitly to collect
633
+ # the fixtures in the init module, but strip "__init__.py" from the baseid
634
+ # Possibly related to https://github.com/pytest-dev/pytest/issues/4085
635
+ collector .obj .__pytest_asyncio_scoped_event_loop = scoped_event_loop
636
+ fixturemanager = collector .config .pluginmanager .get_plugin ("funcmanage" )
637
+ package_node_id = _removesuffix (collector .nodeid , "__init__.py" )
638
+ fixturemanager .parsefactories (collector .obj , nodeid = package_node_id )
639
+ return collector .__original_collect ()
640
+
623
641
collector .__original_collect = collector .collect
624
642
collector .collect = _patched_collect
625
643
else :
@@ -628,17 +646,6 @@ def _patched_collect():
628
646
if pyobject is None :
629
647
return
630
648
pyobject .__pytest_asyncio_scoped_event_loop = scoped_event_loop
631
- # When collector is a package, collector.obj is the package's __init__.py.
632
- # pytest doesn't seem to collect fixtures in __init__.py.
633
- # Using parsefactories to collect fixtures in __init__.py their baseid will end
634
- # with "__init__.py", thus limiting the scope of the fixture to the init module.
635
- # Therefore, we tell the pluginmanager explicitly to collect the fixtures
636
- # in the init module, but strip "__init__.py" from the baseid
637
- # Possibly related to https://github.com/pytest-dev/pytest/issues/4085
638
- if isinstance (collector , Package ):
639
- fixturemanager = collector .config .pluginmanager .get_plugin ("funcmanage" )
640
- package_node_id = _removesuffix (collector .nodeid , "__init__.py" )
641
- fixturemanager .parsefactories (collector .obj , nodeid = package_node_id )
642
649
643
650
644
651
def _removesuffix (s : str , suffix : str ) -> str :
0 commit comments