Add asyncio markers as early as possible to match with pytest-async
@@ -42,15 +42,19 @@ def pytest_addoption(parser):
parser.addoption("--with-e2e", action="store_true", help="Include end-to-end tests.")
+# Make all tests in this directory and below asyncio-compatible by default.
+# Due to how pytest-async checks for these markers, they should be added as early as possible.
+@pytest.hookimpl(hookwrapper=True)
+def pytest_pycollect_makeitem(collector, name, obj):
+ if collector.funcnamefilter(name) and asyncio.iscoroutinefunction(obj):
+ pytest.mark.asyncio(obj)
+ yield
+
+
# This logic is not applied if pytest is started explicitly on ./examples/.
# In that case, regular pytest behaviour applies -- this is intended.
def pytest_collection_modifyitems(config, items):
- # Make all tests in this directory and below asyncio-compatible by default.
- for item in items:
- if asyncio.iscoroutinefunction(item.function):
- item.add_marker('asyncio')
-
# Put all e2e tests to the end, as they are assumed to be slow.
def _is_e2e(item):
path = item.location[0]
