From 2c3af1e3e8beb9702b640d7d883d9c9fe27e8dc7 Mon Sep 17 00:00:00 2001 From: fjetter Date: Thu, 27 May 2021 16:20:34 +0200 Subject: [PATCH 1/2] Resolve pytest-asyncio pinning --- conftest.py | 27 +++++++++++++++++++++ continuous_integration/environment-3.7.yaml | 2 +- continuous_integration/environment-3.8.yaml | 2 +- continuous_integration/environment-3.9.yaml | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/conftest.py b/conftest.py index e8a159fa4a3..1aeb3dedc78 100644 --- a/conftest.py +++ b/conftest.py @@ -32,3 +32,30 @@ def pytest_collection_modifyitems(config, items): pytest_plugins = ["distributed.pytest_resourceleaks"] + +# The following fixtures are required for pytest-asyncio compatibility + + +@pytest.fixture() +def event_loop(): + from distributed.utils_test import pristine_loop + + with pristine_loop() as loop: + yield loop.asyncio_loop + + +@pytest.hookimpl(trylast=True) +def pytest_fixture_post_finalizer(fixturedef, request): + """Pytest-asyncio resets the eventloop policy after the above event loop is closed.""" + import asyncio + + if fixturedef.argname == "event_loop": + try: + # Tornado > 6.0.3 + from tornado.platform.asyncio import AnyThreadEventLoopPolicy + except ImportError: + try: + from distributed.utils import AnyThreadEventLoopPolicy + except ImportError: + return + asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy()) diff --git a/continuous_integration/environment-3.7.yaml b/continuous_integration/environment-3.7.yaml index bb7838fe205..d0f5703606d 100644 --- a/continuous_integration/environment-3.7.yaml +++ b/continuous_integration/environment-3.7.yaml @@ -24,7 +24,7 @@ dependencies: - prometheus_client - psutil - pytest - - pytest-asyncio<0.14.0 + - pytest-asyncio - pytest-faulthandler - pytest-repeat - pytest-rerunfailures diff --git a/continuous_integration/environment-3.8.yaml b/continuous_integration/environment-3.8.yaml index 118d4231e4b..64d1e0f0549 100644 --- a/continuous_integration/environment-3.8.yaml +++ b/continuous_integration/environment-3.8.yaml @@ -22,7 +22,7 @@ dependencies: - prometheus_client - psutil - pytest - - pytest-asyncio<0.14.0 + - pytest-asyncio - pytest-faulthandler - pytest-repeat - pytest-rerunfailures diff --git a/continuous_integration/environment-3.9.yaml b/continuous_integration/environment-3.9.yaml index fa0a661a96b..bd0140229a1 100644 --- a/continuous_integration/environment-3.9.yaml +++ b/continuous_integration/environment-3.9.yaml @@ -24,7 +24,7 @@ dependencies: - prometheus_client - psutil - pytest - - pytest-asyncio<0.14.0 + - pytest-asyncio - pytest-faulthandler - pytest-repeat - pytest-rerunfailures From 2a3c49e2dd6773c28f6fd19e2e1f2f59f17253e6 Mon Sep 17 00:00:00 2001 From: fjetter Date: Thu, 27 May 2021 17:09:11 +0200 Subject: [PATCH 2/2] Use clean instead of pristine loop --- conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conftest.py b/conftest.py index 1aeb3dedc78..010426fa611 100644 --- a/conftest.py +++ b/conftest.py @@ -38,9 +38,9 @@ def pytest_collection_modifyitems(config, items): @pytest.fixture() def event_loop(): - from distributed.utils_test import pristine_loop + from distributed.utils_test import clean - with pristine_loop() as loop: + with clean() as loop: yield loop.asyncio_loop