File tree Expand file tree Collapse file tree 1 file changed +41
-11
lines changed Expand file tree Collapse file tree 1 file changed +41
-11
lines changed Original file line number Diff line number Diff line change 1
1
"""Tests for the Flaky integration, which retries failed tests.
2
2
"""
3
- import asyncio
4
3
5
- import flaky
6
- import pytest
7
4
8
- _threshold = - 1
5
+ from textwrap import dedent
9
6
7
+ pytest_plugins = "pytester"
10
8
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
+ )
You can’t perform that action at this time.
0 commit comments