forked from pytest-dev/pytest-asyncio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_event_loop_fixture_override_deprecation.py
81 lines (66 loc) · 2.02 KB
/
test_event_loop_fixture_override_deprecation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from textwrap import dedent
from pytest import Pytester
def test_emit_warning_when_event_loop_fixture_is_redefined(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import asyncio
import pytest
@pytest.fixture
def event_loop():
loop = asyncio.new_event_loop()
yield loop
loop.close()
@pytest.mark.asyncio
async def test_emits_warning():
pass
@pytest.mark.asyncio
async def test_emits_warning_when_referenced_explicitly(event_loop):
pass
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=2, warnings=2)
def test_does_not_emit_warning_when_no_test_uses_the_event_loop_fixture(
pytester: Pytester,
):
pytester.makepyfile(
dedent(
"""\
import asyncio
import pytest
@pytest.fixture
def event_loop():
loop = asyncio.new_event_loop()
yield loop
loop.close()
def test_emits_no_warning():
pass
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1, warnings=0)
def test_emit_warning_when_redefined_event_loop_is_used_by_fixture(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import asyncio
import pytest
import pytest_asyncio
@pytest.fixture
def event_loop():
loop = asyncio.new_event_loop()
yield loop
loop.close()
@pytest_asyncio.fixture
async def uses_event_loop():
pass
def test_emits_warning(uses_event_loop):
pass
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1, warnings=1)