0
0
PyTesttesting~5 mins

Flaky test detection and retry in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a flaky test?
A flaky test is a test that sometimes passes and sometimes fails without any changes in the code. It behaves unpredictably.
Click to reveal answer
beginner
Why is flaky test detection important?
Detecting flaky tests helps keep the test suite reliable. It prevents false failures that waste time and hide real problems.
Click to reveal answer
intermediate
How can pytest help retry flaky tests?
Pytest can use the 'pytest-rerunfailures' plugin to automatically rerun failed tests a set number of times before marking them as failed.
Click to reveal answer
intermediate
Show a simple pytest example to retry a flaky test up to 3 times.
Use the decorator @pytest.mark.flaky(reruns=3) on the test function. This reruns the test up to 3 times if it fails.
Click to reveal answer
advanced
What is a good practice to reduce flaky tests besides retrying?
Fix the root cause of flakiness by improving test isolation, avoiding timing issues, and using mocks or stubs for unstable dependencies.
Click to reveal answer
What does a flaky test do?
AAlways fails
BSometimes passes and sometimes fails without code changes
CAlways passes
DRuns faster than other tests
Which pytest plugin helps retry failed tests?
Apytest-html
Bpytest-cov
Cpytest-mock
Dpytest-rerunfailures
How do you specify retry count for flaky tests in pytest?
A@pytest.mark.flaky(reruns=3)
Bpytest.retry(3)
Cpytest.flaky(3)
Dpytest.rerun(3)
What is NOT a good way to reduce flaky tests?
AFix timing issues
BUse mocks for unstable parts
CIgnore flaky tests forever
DImprove test isolation
If a test fails once but passes on retry, what does it indicate?
APossible flakiness
BTest is perfect
CCode is broken
DTest is slow
Explain what a flaky test is and why it is a problem in software testing.
Think about tests that don't behave the same every time.
You got /4 concepts.
    Describe how you can use pytest to detect and retry flaky tests.
    Focus on the tools and settings in pytest.
    You got /4 concepts.