0
0
Testing Fundamentalstesting~10 mins

Flaky test management in Testing Fundamentals - 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 in pytest.

Testing Fundamentals
@pytest.mark.[1]
def test_example():
    assert True
Drag options to blanks, or click blank then click option'
Aparametrize
Bskip
Cflaky
Dslow
Attempts:
3 left
💡 Hint
Common Mistakes
Using @pytest.mark.skip will skip the test instead of marking it flaky.
Using @pytest.mark.parametrize is for running tests with multiple inputs.
2fill in blank
medium

Complete the code to retry a flaky test up to 3 times using pytest-rerunfailures.

Testing Fundamentals
@pytest.mark.flaky(reruns=[1])
def test_flaky():
    assert random.choice([True, False])
Drag options to blanks, or click blank then click option'
A3
B1
C5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting reruns=0 disables retries.
Setting reruns=1 retries only once, which may be insufficient.
3fill in blank
hard

Fix the error in the flaky test decorator syntax.

Testing Fundamentals
@pytest.mark.flaky(reruns=[1])
def test_network():
    assert ping_server()
Drag options to blanks, or click blank then click option'
A'3'
BNone
CTrue
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string '3' causes a type error.
Using True or None is invalid for reruns parameter.
4fill in blank
hard

Fill both blanks to create a dictionary of test names and their flaky status.

Testing Fundamentals
flaky_tests = {test_name: [1] for test_name in tests if tests[test_name] [2] True}
Drag options to blanks, or click blank then click option'
Atests[test_name]
Btest_name
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using test_name as value instead of flaky status.
Using '!=' instead of '==' causes wrong filtering.
5fill in blank
hard

Fill both blanks to filter flaky tests and print their names.

Testing Fundamentals
for test, is_flaky in tests.items():
    if is_flaky [1] True:
        print(test,'Flaky test detected: '[2] test)
Drag options to blanks, or click blank then click option'
A==
B!=
C+
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' reverses the condition.
Using '+' instead of ',' in print causes syntax errors.
Using ',' instead of '+' for string concatenation inside print.