forked from pytest-dev/pytest-asyncio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_is_async_test.py
107 lines (90 loc) · 2.89 KB
/
test_is_async_test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from textwrap import dedent
import pytest
from pytest import Pytester
def test_returns_false_for_sync_item(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import pytest
import pytest_asyncio
def test_sync():
pass
def pytest_collection_modifyitems(items):
async_tests = [
item
for item in items
if pytest_asyncio.is_async_test(item)
]
assert len(async_tests) == 0
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1)
def test_returns_true_for_marked_coroutine_item_in_strict_mode(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import pytest
import pytest_asyncio
@pytest.mark.asyncio
async def test_coro():
pass
def pytest_collection_modifyitems(items):
async_tests = [
item
for item in items
if pytest_asyncio.is_async_test(item)
]
assert len(async_tests) == 1
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1)
def test_returns_false_for_unmarked_coroutine_item_in_strict_mode(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import pytest
import pytest_asyncio
async def test_coro():
pass
def pytest_collection_modifyitems(items):
async_tests = [
item
for item in items
if pytest_asyncio.is_async_test(item)
]
assert len(async_tests) == 0
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
if pytest.version_tuple < (7, 2):
# Probably related to https://github.com/pytest-dev/pytest/pull/10012
result.assert_outcomes(failed=1)
elif pytest.version_tuple < (8,):
result.assert_outcomes(skipped=1)
else:
result.assert_outcomes(failed=1)
def test_returns_true_for_unmarked_coroutine_item_in_auto_mode(pytester: Pytester):
pytester.makepyfile(
dedent(
"""\
import pytest
import pytest_asyncio
async def test_coro():
pass
def pytest_collection_modifyitems(items):
async_tests = [
item
for item in items
if pytest_asyncio.is_async_test(item)
]
assert len(async_tests) == 1
"""
)
)
result = pytester.runpytest("--asyncio-mode=auto")
result.assert_outcomes(passed=1)