Kindly be informed that the coverage will check for the .coverage file to read and create that report for you. Py.test on its own will not e able to create the report. You need py.test plugin for coverage:
pip install pytest-cov
If it is there already then you can run both at once like this:
py.test test.py --cov=sample.py
The above code will run the test module test.py and then it will record or illustrate the coverage report on sample.py.
If you need to have many test runs and you have incorporated their recorded coverage and then it will display a final report, you can run it like this:
py.test test.py --cov=sample.py --cov-report=
py.test test.py --cov=sample2.py --cov-report=
py.test test.py --cov=sample3.py --cov-report=
Then the run test module that is test.py and record (only) coverage on sample.py - don't illustrate a report. Now you can run the coverage command separately for a complete report:
coverage report -m
The command above simply displays a formatted coverage report based on the accumulated .coverage data file from previous test runs. -m means show lines missed i.e. lines not covered by tests:
Name Stmts Miss Cover Missing
-----------------------------------------
sample.py 6 0 100%
Coverage supports more switches like --include and --omit to include/exclude files using path patterns.
Join this Python Training course now if you want to gain more knowledge in Python.