Skip to content

Rewrite flaky integration test to don't pollute the output with flaky restart warnings #246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions tests/test_flaky_integration.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
"""Tests for the Flaky integration, which retries failed tests.
"""
import asyncio

import flaky
import pytest

_threshold = -1
from textwrap import dedent

pytest_plugins = "pytester"

@flaky.flaky(3, 2)
@pytest.mark.asyncio
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
global _threshold
await asyncio.sleep(0.1)
_threshold += 1
assert _threshold != 1

def test_auto_mode_cmdline(pytester):
pytester.makepyfile(
dedent(
"""\
import asyncio
import flaky
import pytest

_threshold = -1

@flaky.flaky(3, 2)
@pytest.mark.asyncio
async def test_asyncio_flaky_thing_that_fails_then_succeeds():
global _threshold
await asyncio.sleep(0.1)
_threshold += 1
assert _threshold != 1
"""
)
)
# runpytest_subprocess() is required to don't pollute the output
# with flaky restart information
result = pytester.runpytest_subprocess()
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines(
[
"===Flaky Test Report===",
"test_asyncio_flaky_thing_that_fails_then_succeeds passed 1 "
"out of the required 2 times. Running test again until it passes 2 times.",
"test_asyncio_flaky_thing_that_fails_then_succeeds failed "
"(1 runs remaining out of 3).",
" <class 'AssertionError'>",
" assert 1 != 1",
"test_asyncio_flaky_thing_that_fails_then_succeeds passed 2 "
"out of the required 2 times. Success!",
"===End Flaky Test Report===",
]
)