0
0
PyTesttesting~10 mins

Flaky test detection and retry in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to mark a test as flaky using pytest.

PyTest
import pytest

@pytest.[1](reruns=3)
def test_example():
    assert True
Drag options to blanks, or click blank then click option'
Amark
Bmark.flaky
Cmark.flaky(reruns=3)
Dflaky
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'flaky' directly without 'mark'.
Trying to call the decorator instead of using it as an attribute.
2fill in blank
medium

Complete the code to retry a flaky test 5 times with pytest.

PyTest
import pytest

@pytest.mark.flaky(reruns=[1])
def test_retry():
    assert False
Drag options to blanks, or click blank then click option'
A5
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting reruns to 0 disables retries.
Using a string instead of an integer.
3fill in blank
hard

Fix the error in the flaky test decorator syntax.

PyTest
import pytest

@pytest.mark.flaky(reruns=[1])
def test_fail():
    assert False
Drag options to blanks, or click blank then click option'
A'3'
Bthree
C3
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer for reruns.
Passing None which disables retries.
4fill in blank
hard

Fill both blanks to retry a flaky test 4 times and delay retries by 2 seconds.

PyTest
import pytest

@pytest.mark.flaky(reruns=[1], reruns_delay=[2])
def test_delayed_retry():
    assert False
Drag options to blanks, or click blank then click option'
A4
B2
C3
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up reruns and reruns_delay values.
Using strings instead of integers.
5fill in blank
hard

Fill all three blanks to retry a flaky test 3 times, delay 1 second between retries, and only rerun on AssertionError.

PyTest
import pytest

@pytest.mark.flaky(reruns=[1], reruns_delay=[2], reruns_exceptions=[3])
def test_specific_exception():
    assert False
Drag options to blanks, or click blank then click option'
A3
B1
C(AssertionError,)
D(Exception,)
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong exception types for reruns_exceptions.
Forgetting to use a tuple for exceptions.