Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 1 KB

File metadata and controls

52 lines (31 loc) · 1 KB

Chapter 9. Coverage.


AUT: Cards (To-Do List)

1. pytest-cov

Installation: pip install pytest-cov

Coverage command: pytest --cov=cards --cov-report=term-missing <test_path> --cov={path to the code or the installed package you're testing}

2. coverage

Installation: pip install coverage

Coverage command: coverage run --source=cards -m pytest <test_path>

Report: coverage report --show-missing

Coverage spec file:

[paths]
source = 
    path_1
    path_2

3. HTML Reports

pytest --cov=cards --cov-report=html <test_path>

or:

pytest --cov=cards <test_path>

coverage html

4. Excluding Code from Coverage

Code blocks can be excluded from testing with pragma statement.

def main():
    ...


if __name__ == "__main__":  # pragma: no cover
    main()