Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to run tests automatically in CI.
PyTest
def test_addition(): assert 2 + 2 == [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a wrong sum like 5 or 3.
✗ Incorrect
The test checks if 2 + 2 equals 4, which is correct.
2fill in blank
mediumComplete the code to mark a test to run in CI only.
PyTest
@pytest.mark.[1] def test_feature(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using skip or slow markers which do not indicate CI.
✗ Incorrect
Marking tests with @pytest.mark.ci helps identify tests to run in CI pipelines.
3fill in blank
hardFix the error in the test command to run tests in CI.
PyTest
pytest [1] tests/ Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect flags like --run or --ci.
✗ Incorrect
The correct pytest option to run tests with a marker is '-m ci'.
4fill in blank
hardFill both blanks to create a test that fails if coverage is below 80%.
PyTest
pytest --cov=myapp --cov-fail-under=[1] --cov-report=[2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using too high coverage threshold or wrong report type.
✗ Incorrect
Setting --cov-fail-under=80 enforces minimum coverage. 'term-missing' shows missing lines in terminal.
5fill in blank
hardFill all three blanks to create a test report dictionary filtering passed tests.
PyTest
report = {test: result for test, result in results.items() if result [1] 'passed' and test.startswith([2]) and len(test) [3] 10} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' or wrong string prefix.
✗ Incorrect
The code filters tests where result equals 'passed', test names start with 'test_', and test name length is less than 10.