Skip to content

Commit 396a372

Browse files
committed
Add asyncio markers as early as possible to match with pytest-async
1 parent ef17bfd commit 396a372

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tests/conftest.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ def pytest_addoption(parser):
4242
parser.addoption("--with-e2e", action="store_true", help="Include end-to-end tests.")
4343

4444

45+
# Make all tests in this directory and below asyncio-compatible by default.
46+
# Due to how pytest-async checks for these markers, they should be added as early as possible.
47+
@pytest.hookimpl(hookwrapper=True)
48+
def pytest_pycollect_makeitem(collector, name, obj):
49+
if collector.funcnamefilter(name) and asyncio.iscoroutinefunction(obj):
50+
pytest.mark.asyncio(obj)
51+
yield
52+
53+
4554
# This logic is not applied if pytest is started explicitly on ./examples/.
4655
# In that case, regular pytest behaviour applies -- this is intended.
4756
def pytest_collection_modifyitems(config, items):
4857

49-
# Make all tests in this directory and below asyncio-compatible by default.
50-
for item in items:
51-
if asyncio.iscoroutinefunction(item.function):
52-
item.add_marker('asyncio')
53-
5458
# Put all e2e tests to the end, as they are assumed to be slow.
5559
def _is_e2e(item):
5660
path = item.location[0]

0 commit comments

Comments
 (0)