diff --git a/requirements.txt b/requirements.txt index 53c6398b..598f2e17 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,10 +4,10 @@ # Everything needed to develop (test, debug) the framework. coverage<5.0 # manual enforcement where pip fails, see #272. pytest-aiohttp -pytest-asyncio -pytest-mock>=1.11.1 +pytest-asyncio==0.10.0 # until fixed: https://github.com/pytest-dev/pytest-asyncio/issues/154 +pytest-mock pytest-cov -pytest +pytest==5.3.5 # until fixed: https://github.com/pytest-dev/pytest-asyncio/issues/154 aresponses asynctest freezegun diff --git a/tests/conftest.py b/tests/conftest.py index b149fa13..6471bcf7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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]