Skip to content

Commit

Permalink
Fixed uvloop loops leaking to regular asyncio tests
Browse files Browse the repository at this point in the history
Previously, when uvloop was installed, it would get set as the event loop policy and was never replaced with the default policy, contrary to how the tests were supposed to be run. This change makes sure that the default event loop policy is restored when uvloop should not be in use.
  • Loading branch information
agronholm committed Jul 30, 2020
1 parent 7eef483 commit 330df34
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest

uvloop_marks = []
uvloop_policy = None
try:
import uvloop
except ImportError:
Expand All @@ -12,11 +13,13 @@
and not hasattr(uvloop.loop.Loop, 'shutdown_default_executor')):
uvloop_marks.append(
pytest.mark.skip(reason='uvloop is missing shutdown_default_executor()'))
else:
uvloop_policy = uvloop.EventLoopPolicy()


@pytest.fixture(params=[
pytest.param(('asyncio', {'use_uvloop': False}), id='asyncio'),
pytest.param(('asyncio', {'use_uvloop': True}), id='asyncio+uvloop', marks=uvloop_marks),
pytest.param(('asyncio', {'policy': asyncio.DefaultEventLoopPolicy()}), id='asyncio'),
pytest.param(('asyncio', {'policy': uvloop_policy}), id='asyncio+uvloop', marks=uvloop_marks),
pytest.param('curio'),
pytest.param('trio')
], autouse=True)
Expand Down

0 comments on commit 330df34

Please sign in to comment.