Challenge - 5 Problems
Flaky Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this flaky test retry code?
Consider this pytest test with a retry decorator that reruns the test up to 3 times if it fails. What will be the final test result after running this test?
PyTest
import pytest import random @pytest.mark.flaky(reruns=3) def test_random_fail(): assert random.choice([True, False])
Attempts:
2 left
💡 Hint
The reruns parameter allows retrying the test if it fails up to the given number of times.
✗ Incorrect
The @pytest.mark.flaky decorator with reruns=3 retries the test up to 3 times if it fails. If any retry passes, the test is marked as passed.
❓ assertion
intermediate2:00remaining
Which assertion correctly detects flaky test retry success?
You want to assert that a flaky test retried up to 2 times eventually passes. Which assertion correctly checks this in pytest?
Attempts:
2 left
💡 Hint
Check both the number of reruns and the final pass status.
✗ Incorrect
To confirm a flaky test passed after retries, ensure rerun_count is within limit and the test passed.
🔧 Debug
advanced2:00remaining
Why does this flaky test retry decorator not work as expected?
This pytest test uses a retry decorator but never retries on failure. Identify the bug.
PyTest
import pytest def retry_test(func): def wrapper(): for _ in range(3): try: func() break except AssertionError: pass else: raise AssertionError("Test failed after retries") return wrapper @retry_test def test_always_fail(): assert False
Attempts:
2 left
💡 Hint
Pytest needs the test to raise AssertionError to mark failure.
✗ Incorrect
The decorator swallows AssertionError and never re-raises it after retries, so pytest thinks the test passed.
🧠 Conceptual
advanced2:00remaining
What is the main risk of using flaky test retries without fixing root causes?
Why is relying on flaky test retries considered a bad practice in software testing?
Attempts:
2 left
💡 Hint
Think about test trustworthiness and maintenance.
✗ Incorrect
Retries can mask flaky tests instead of fixing them, leading to unreliable test suites and missed bugs.
❓ framework
expert2:00remaining
Which pytest plugin and option enable automatic flaky test retries with reporting?
You want to automatically retry flaky tests up to 5 times and see retry counts in the test report. Which plugin and command line option achieve this?
Attempts:
2 left
💡 Hint
Look for the plugin designed specifically for rerunning failed tests.
✗ Incorrect
pytest-rerunfailures plugin supports --reruns option to retry failed tests and reports retry counts.