Skip to content

Commit b6b2c7f

Browse files
committed
[refactor] Simplified code in test_asyncio_mark.
Tests use command-line arguments to set the asyncio mode and warnings filter, instead of a .ini file. This reduces the number of lines in the test module significantly. Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
1 parent 4bca1d7 commit b6b2c7f

File tree

1 file changed

+7
-84
lines changed

1 file changed

+7
-84
lines changed

tests/test_asyncio_mark.py

Lines changed: 7 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,7 @@ def test_a():
1515
"""
1616
)
1717
)
18-
pytester.makefile(
19-
".ini",
20-
pytest=dedent(
21-
"""\
22-
[pytest]
23-
asyncio_mode = strict
24-
filterwarnings =
25-
default
26-
"""
27-
),
28-
)
29-
result = pytester.runpytest()
18+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
3019
result.assert_outcomes(passed=1)
3120
result.stdout.fnmatch_lines(
3221
["*is marked with '@pytest.mark.asyncio' but it is not an async function.*"]
@@ -47,18 +36,7 @@ async def test_a():
4736
"""
4837
)
4938
)
50-
pytester.makefile(
51-
".ini",
52-
pytest=dedent(
53-
"""\
54-
[pytest]
55-
asyncio_mode = strict
56-
filterwarnings =
57-
default
58-
"""
59-
),
60-
)
61-
result = pytester.runpytest()
39+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
6240
result.assert_outcomes(xfailed=1, warnings=1)
6341
result.stdout.fnmatch_lines(
6442
["*Tests based on asynchronous generators are not supported*"]
@@ -76,18 +54,7 @@ async def test_a():
7654
"""
7755
)
7856
)
79-
pytester.makefile(
80-
".ini",
81-
pytest=dedent(
82-
"""\
83-
[pytest]
84-
asyncio_mode = auto
85-
filterwarnings =
86-
default
87-
"""
88-
),
89-
)
90-
result = pytester.runpytest()
57+
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
9158
result.assert_outcomes(xfailed=1, warnings=1)
9259
result.stdout.fnmatch_lines(
9360
["*Tests based on asynchronous generators are not supported*"]
@@ -109,18 +76,7 @@ async def test_a(self):
10976
"""
11077
)
11178
)
112-
pytester.makefile(
113-
".ini",
114-
pytest=dedent(
115-
"""\
116-
[pytest]
117-
asyncio_mode = strict
118-
filterwarnings =
119-
default
120-
"""
121-
),
122-
)
123-
result = pytester.runpytest()
79+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
12480
result.assert_outcomes(xfailed=1, warnings=1)
12581
result.stdout.fnmatch_lines(
12682
["*Tests based on asynchronous generators are not supported*"]
@@ -140,18 +96,7 @@ async def test_a():
14096
"""
14197
)
14298
)
143-
pytester.makefile(
144-
".ini",
145-
pytest=dedent(
146-
"""\
147-
[pytest]
148-
asyncio_mode = auto
149-
filterwarnings =
150-
default
151-
"""
152-
),
153-
)
154-
result = pytester.runpytest()
99+
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
155100
result.assert_outcomes(xfailed=1, warnings=1)
156101
result.stdout.fnmatch_lines(
157102
["*Tests based on asynchronous generators are not supported*"]
@@ -174,18 +119,7 @@ async def test_a():
174119
"""
175120
)
176121
)
177-
pytester.makefile(
178-
".ini",
179-
pytest=dedent(
180-
"""\
181-
[pytest]
182-
asyncio_mode = strict
183-
filterwarnings =
184-
default
185-
"""
186-
),
187-
)
188-
result = pytester.runpytest()
122+
result = pytester.runpytest("--asyncio-mode=strict", "-W default")
189123
result.assert_outcomes(xfailed=1, warnings=1)
190124
result.stdout.fnmatch_lines(
191125
["*Tests based on asynchronous generators are not supported*"]
@@ -205,18 +139,7 @@ async def test_a():
205139
"""
206140
)
207141
)
208-
pytester.makefile(
209-
".ini",
210-
pytest=dedent(
211-
"""\
212-
[pytest]
213-
asyncio_mode = auto
214-
filterwarnings =
215-
default
216-
"""
217-
),
218-
)
219-
result = pytester.runpytest()
142+
result = pytester.runpytest("--asyncio-mode=auto", "-W default")
220143
result.assert_outcomes(xfailed=1, warnings=1)
221144
result.stdout.fnmatch_lines(
222145
["*Tests based on asynchronous generators are not supported*"]

0 commit comments

Comments
 (0)