0
0
PyTesttesting~5 mins

pytest-cov for coverage - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is pytest-cov used for?

pytest-cov is a plugin for pytest that measures how much of your code is tested by your tests. It shows which parts of the code were run and which were missed.

Click to reveal answer
beginner
How do you install pytest-cov?

You install it using pip with the command: pip install pytest-cov. This adds coverage support to your pytest tests.

Click to reveal answer
beginner
What command runs tests with coverage report in the terminal?

Use pytest --cov=your_package to run tests and see coverage in the terminal. Replace your_package with your code folder or module name.

Click to reveal answer
intermediate
How can you generate an HTML coverage report with pytest-cov?

Add --cov-report=html to your pytest command. For example: pytest --cov=your_package --cov-report=html. This creates a folder htmlcov with a detailed report you can open in a browser.

Click to reveal answer
beginner
Why is measuring test coverage important?

Coverage helps you see which parts of your code are tested and which are not. This helps find missing tests and improve code quality by making sure important parts are checked.

Click to reveal answer
What does pytest-cov measure?
ANumber of tests passed
BHow fast your tests run
CHow much of your code is executed by tests
DMemory usage during tests
Which command installs pytest-cov?
Apip install pytest-cov
Bnpm install pytest-cov
Cpytest install cov
Dpip install coverage
How do you run tests with coverage for a package named app?
Apytest --run app
Bpytest --coverage app
Cpytest --cov-report=app
Dpytest --cov=app
What does --cov-report=html do?
AGenerates an HTML coverage report
BRuns tests in HTML mode
CSaves coverage data as HTML files
DDisables coverage reporting
Why should you check test coverage?
ATo speed up tests
BTo find untested code parts
CTo reduce code size
DTo increase test failures
Explain how to use pytest-cov to measure and report test coverage for a Python project.
Think about installation, running tests, and generating reports.
You got /5 concepts.
    Why is test coverage useful and how can pytest-cov help improve your tests?
    Consider the benefits of knowing what your tests cover.
    You got /5 concepts.