Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the coverage module.
PyTest
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing pytest instead of coverage
Using unittest which is for testing but not coverage
✗ Incorrect
The coverage module is used to measure how much of your code is tested.
2fill in blank
mediumComplete the code to start coverage measurement before tests.
PyTest
cov = coverage.Coverage()
cov.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling stop() before tests
Using report() which is for showing results
✗ Incorrect
We call start() to begin measuring coverage before running tests.
3fill in blank
hardFix the error in the code to stop coverage after tests.
PyTest
cov.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling start() again
Using non-existent methods like begin or end
✗ Incorrect
After tests finish, we call stop() to end coverage measurement.
4fill in blank
hardFill both blanks to generate and save the coverage report.
PyTest
cov.[1]() cov.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling start or stop instead of report or save
Reversing the order of methods
✗ Incorrect
First, report() prints the coverage summary, then save() saves the data.
5fill in blank
hardFill all three blanks to run tests with coverage and print the report.
PyTest
cov = coverage.Coverage() cov.[1]() # run tests here cov.[2]() cov.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using save instead of report at the end
Stopping coverage before tests
✗ Incorrect
We start coverage, run tests, stop coverage, then print the report.