Skip to content

Commit ef42a83

Browse files
authored
Update test_run.py
1 parent 8db1046 commit ef42a83

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

tests/test_run.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55

66
import qasync
77

8-
9-
def test_run_with_contextmanager(application):
8+
@pytest.fixture
9+
def get_event_loop_coro(expected_loop):
1010
async def coro():
1111
event_loop = asyncio.get_event_loop()
12-
assert (
13-
type(event_loop).__name__ == "QIOCPEventLoop"
14-
if os.name == "nt"
15-
else "QSelectorEventLoop"
16-
)
12+
13+
assert type(event_loop).__name__ == expected_loop
1714
await asyncio.sleep(0)
15+
return coro
16+
17+
@pytest.fixture
18+
def expected_loop():
19+
return "QIOCPEventLoop" if os.name == "nt" else "QSelectorEventLoop"
1820

21+
def test_run_with_contextmanager(get_event_loop_coro):
1922
asyncio.set_event_loop(None)
20-
qasync.run(coro())
23+
qasync.run(get_event_loop_coro())
2124

2225
with pytest.raises(RuntimeError):
2326
_ = asyncio.get_event_loop()
27+
28+
def test_run_with_existing_eventloop(get_event_loop_coro, expected_loop):
29+
asyncio.set_event_loop(asyncio.new_event_loop())
30+
qasync.run(get_event_loop_coro())
31+
assert asyncio.get_event_loop() != expected_loop

0 commit comments

Comments
 (0)