Closed chris-sanders closed 3 years ago
There are explicit tests upstream to ensure that the scope change pattern works, so I'm confused as to why the monkey patching would be needed. It also looks like this may be a regression with 0.14, possibly because of the changed mentioned in this bug.
There are explicit tests upstream to ensure that the scope change pattern works
Yeah, but they're testing it in a test_*.py file which is guaranteed to have pytest-asyncio loaded before it runs.
I think the problem here is that sometimes pytest-operator loads before pytest-asyncio, and when that happens, pytest-operator's module-scoped event_loop fixture gets overridden by the pytest-asyncio default event_loop fixture.
Plugin load order is partially defined, but not well defined between plugins discovered via setuptools entrypoints and not controllable by plugin authors.
Currently, the monkey-patch in this PR is the only way I see to fix this at the plugin level. Nasty as it is, it makes it so the plugin load order doesn't matter.
The other solution I see, short of rearchitecting this whole project, is to require users of pytest-operator to invoke pytest with -p pytest-asyncio
, guaranteeing pytest-asyncio loads first.
Hrm. If the pytest-asyncio isn't discovered and registered yet, I wonder if the monkey patch could potentially fail? Another possible approach would be to leverage the pytest_plugin_registered hook, but I'm not sure if that would be cleaner or not.
Released as 0.6.1
I can't find any way for plugins to choose their order of loading. You can monkey patch the asyncio plugin from the operator plugin though.