forked from pytest-dev/pytest-asyncio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_invalid_arguments.py
85 lines (72 loc) · 2.01 KB
/
test_invalid_arguments.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
from textwrap import dedent
import pytest
def test_no_error_when_scope_passed_as_sole_keyword_argument(
pytester: pytest.Pytester,
):
pytester.makepyfile(
dedent(
"""\
import pytest
@pytest.mark.asyncio(loop_scope="session")
async def test_anything():
pass
"""
)
)
result = pytester.runpytest_subprocess()
result.assert_outcomes(passed=1)
result.stdout.no_fnmatch_line("*ValueError*")
def test_error_when_scope_passed_as_positional_argument(
pytester: pytest.Pytester,
):
pytester.makepyfile(
dedent(
"""\
import pytest
@pytest.mark.asyncio("session")
async def test_anything():
pass
"""
)
)
result = pytester.runpytest_subprocess()
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(
["*ValueError: mark.asyncio accepts only a keyword argument*"]
)
def test_error_when_wrong_keyword_argument_is_passed(
pytester: pytest.Pytester,
):
pytester.makepyfile(
dedent(
"""\
import pytest
@pytest.mark.asyncio(cope="session")
async def test_anything():
pass
"""
)
)
result = pytester.runpytest_subprocess()
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(
["*ValueError: mark.asyncio accepts only a keyword argument 'scope'*"]
)
def test_error_when_additional_keyword_arguments_are_passed(
pytester: pytest.Pytester,
):
pytester.makepyfile(
dedent(
"""\
import pytest
@pytest.mark.asyncio(loop_scope="session", more="stuff")
async def test_anything():
pass
"""
)
)
result = pytester.runpytest_subprocess()
result.assert_outcomes(errors=1)
result.stdout.fnmatch_lines(
["*ValueError: mark.asyncio accepts only a keyword argument*"]
)