Skip to content

Commit a373885

Browse files
committed
Clean up properly.
1 parent 8cc38ee commit a373885

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pytest_asyncio/plugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ def pytest_fixture_setup(fixturedef, request):
7878
asyncio.get_child_watcher().attach_loop(loop)
7979
fixturedef.addfinalizer(lambda: asyncio.set_event_loop_policy(policy))
8080
else:
81+
old_loop = policy.get_event_loop()
8182
policy.set_event_loop(loop)
83+
fixturedef.addfinalizer(lambda: policy.set_event_loop(old_loop))
8284

8385

8486
@asyncio.coroutine

tests/test_event_loop_scope.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Test the event loop fixture is properly disposed of.
2+
3+
These tests need to be run together.
4+
"""
5+
import asyncio
6+
import pytest
7+
8+
9+
def test_1():
10+
loop = asyncio.get_event_loop()
11+
assert not loop.is_closed()
12+
13+
14+
@pytest.mark.asyncio
15+
async def test_2():
16+
pass
17+
18+
19+
def test_3():
20+
loop = asyncio.get_event_loop()
21+
assert not loop.is_closed()

0 commit comments

Comments
 (0)