For full information, please reffer to https://medium.com/@khalid.nwb/a-quick-intro-to-to-test-coverage-in-python-9bf299711c6c
$ pip install coverage
If you are using anaconda distribution, you can use:
$ conda install coverage
You can verify your Coverage installation by checking the version:
$ coverage –version
$ coverage run -m pytest arg1 arg2 arg3
$ coverage -m unittest test_code
$ coverage report
$ coverage html
Add a comment after the line "# pragma: no cover"
Install stuff
$ pip3 install coverage
$ pip3 install -U pytest
See https://stackoverflow.com/a/70556981/3412545
$ file="test_tutorial.py" && coverage run $file && coverage report -m $file && coverage xml $file
Name Stmts Miss Cover Missing
------------------------------------------------
test_tutorial.py 17 10 41% 10-15, 18-23
------------------------------------------------
TOTAL 17 10 41%
Wrote XML report to coverage.xml
for
-Dsonar.python.coverage.reportPaths=coverage.xml
pytest --junitxml=py-results1.xml
for
-Dsonar.python.xunit.reportPath=py-results1.xml