Reputation: 53
I want to get the code coverage of a python file say "Test.py". Now, when I write the script for this using coverage.py, it looks like this,
import coverage
cov = coverage.Coverage()
cov.start()
#pass the data
cov.stop()
cov.save()
cov.html_report()
now in place of pass the data, I want to pass Test.py, How can I do this?
Upvotes: 1
Views: 1906
Reputation: 879
I just have the same doubt.
This gave me the result you want using pytest
import coverage
import pytest
cov = coverage.Coverage()
cov.start()
pytest.main(['-x', 'api/tests.py', '-vv'])
cov.stop()
cov.report()
Upvotes: 2
Reputation: 375574
You don't need to use the coverage API. Just run your program with coverage:
$ coverage run Test.py
Upvotes: 0