Recall & Review
beginner
What is pytest-cov used for?
pytest-cov is a plugin for pytest that measures code coverage during test runs. It shows which parts of your code were tested and which were not.
Click to reveal answer
beginner
How do you install pytest-cov?
You install pytest-cov using pip with the command:
pip install pytest-cov.Click to reveal answer
beginner
How do you run pytest with coverage reporting?
Run tests with coverage by using:
pytest --cov=your_package_name. Replace your_package_name with the folder or module you want to check coverage for.Click to reveal answer
intermediate
What does the option
--cov-report=term do?It shows the coverage report directly in the terminal after tests finish, so you can quickly see which lines were covered.
Click to reveal answer
intermediate
How can you generate an HTML coverage report with pytest-cov?
Use the command:
pytest --cov=your_package_name --cov-report=html. This creates a folder named htmlcov with a detailed, easy-to-read coverage report you can open in a browser.Click to reveal answer
Which command installs pytest-cov?
✗ Incorrect
The correct command to install pytest-cov is
pip install pytest-cov.What does
pytest --cov=myapp do?✗ Incorrect
This command runs all tests and measures how much of 'myapp' code is covered by tests.
How do you see coverage results in the terminal?
✗ Incorrect
Use
--cov-report=term to display coverage results in the terminal.Where does pytest-cov put the HTML report by default?
✗ Incorrect
The HTML coverage report is saved in the
htmlcov folder by default.What must you specify to measure coverage for a specific package?
✗ Incorrect
You specify the package or folder name after
--cov= to measure coverage for it.Explain how to set up pytest-cov to measure and report test coverage for a Python project.
Think about installation, running tests, and viewing coverage.
You got /4 concepts.
Describe the benefits of using pytest-cov in your testing workflow.
Consider how coverage helps improve tests.
You got /4 concepts.