Simple Coverage measurements for Python
Project description
simple-coverage
Very basic coverage tool for educational purposes.
Installation
pip install simple-coverage
Usage
Just import the package and add the @print_coverage decorator about functions you want to inspect.
from simple_coverage.coverage import coverage
@print_coverage
def demo(x, y) -> int:
"""
Demo function
"""
product = x * y
if product < 10:
return product * 2
else:
return product
if __name__ == "__main__":
demo(3,5)
When simply runnning the Python-file, this will create the following output:
Function: demo(3, 5)
CALLED line 9: product = x * y
CALLED line 10: if product < 10:
MISSED line 11: return product * 2
IGNORE line 12: else:
CALLED line 13: return product
Instruction coverage: 75.0 %
Branch coverage: 50.0 %
Doctests
If you want to use it with doctests, use the meta wrapper @doctest_wrapper
and the log_coverage
decorator. This will create a simple-coverage.json
file in the current working directory since writing into the console would collide with the doctests.
from simple_coverage.coverage import log_coverage, doctest_wrapper
@doctest_wrapper(log_coverage)
def demo(x,y) -> int:
...
Look at the demo.py
file for reference. To start the doctest use pytest as usual.
pytest --doctest-modules demo.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simple_coverage-0.2.0.tar.gz
(4.4 kB
view hashes)
Built Distribution
Close
Hashes for simple_coverage-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe949e4565867156e09dc06ff8eb7079d96adbb42f534c9d406da9db6c8f31fd |
|
MD5 | 32ae3f564de008d5ce91d289e2ac9310 |
|
BLAKE2b-256 | f3f470b80a71aa24f8d11c82849c13df2a76a8debfe649bc684de88d9b7380f4 |