Skip to content

Commit 5d4954a

Browse files
authored
Rewrite flaky integration test (#246)
to don't pollute the output with flaky restart warnings
1 parent 0a143c4 commit 5d4954a

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

tests/test_flaky_integration.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
"""Tests for the Flaky integration, which retries failed tests.
22
"""
3-
import asyncio
43

5-
import flaky
6-
import pytest
74

8-
_threshold = -1
5+
from textwrap import dedent
96

7+
pytest_plugins = "pytester"
108

11-
@flaky.flaky(3, 2)
12-
@pytest.mark.asyncio
13-
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
14-
global _threshold
15-
await asyncio.sleep(0.1)
16-
_threshold += 1
17-
assert _threshold != 1
9+
10+
def test_auto_mode_cmdline(pytester):
11+
pytester.makepyfile(
12+
dedent(
13+
"""\
14+
import asyncio
15+
import flaky
16+
import pytest
17+
18+
_threshold = -1
19+
20+
@flaky.flaky(3, 2)
21+
@pytest.mark.asyncio
22+
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
23+
global _threshold
24+
await asyncio.sleep(0.1)
25+
_threshold += 1
26+
assert _threshold != 1
27+
"""
28+
)
29+
)
30+
# runpytest_subprocess() is required to don't pollute the output
31+
# with flaky restart information
32+
result = pytester.runpytest_subprocess()
33+
result.assert_outcomes(passed=1)
34+
result.stdout.fnmatch_lines(
35+
[
36+
"===Flaky Test Report===",
37+
"test_asyncio_flaky_thing_that_fails_then_succeeds passed 1 "
38+
"out of the required 2 times. Running test again until it passes 2 times.",
39+
"test_asyncio_flaky_thing_that_fails_then_succeeds failed "
40+
"(1 runs remaining out of 3).",
41+
" <class 'AssertionError'>",
42+
" assert 1 != 1",
43+
"test_asyncio_flaky_thing_that_fails_then_succeeds passed 2 "
44+
"out of the required 2 times. Success!",
45+
"===End Flaky Test Report===",
46+
]
47+
)

0 commit comments

Comments
 (0)