how to get which statements are missed in python test coverage
Asked Answered
R

3

77

I am new to python, I have written test cases for my class , I am using python -m pytest --cov=azuread_api to get code coverage.

I am getting coverage on the console as enter image description here

How do I get which lines are missed by test for e.g in aadadapter.py file

Thanks,

Roshan answered 16/2, 2018 at 10:59 Comment(0)
K
127

If you check the documentation for reporting in pytest-cov, you can see how to manipulate the report and generate extra versions.

For example, adding the option --cov-report term-missing you'll get the missing lines printed in the terminal.

A more user friendly option, would be to generate an html report by usign the --cov-report html option. Then you can navigate to the generated folder (htmlcov by default) and open the index.html with your browser and navigate your source code where the missing lines are highlighted.

Keare answered 16/2, 2018 at 11:9 Comment(0)
L
15

In addition to the answer from Ignacio, one can also set show_missing = true in .coveragerc, as pytest-cov reads that config file as well.

Legionary answered 17/11, 2020 at 2:42 Comment(0)
S
5

To amend @pepoluan's answer pytest-cov can also be configured in pyproject.toml.

#pyproject.toml
[tool.pytest.ini_options]
addopts = "--cov --cov-report term-missing"

Or both, e.g.

#.coveragerc
[report]
show_missing=true

and

#pyproject.toml
[tool.pytest.ini_options]
addopts = "--cov"
Spindell answered 6/4, 2023 at 9:46 Comment(1)
For my case using Poetry, setting up [tools.coverage.report] in my pyproject.toml with show_missing=true did the trickBluegrass

© 2022 - 2024 — McMap. All rights reserved.