Test Coverage

This project uses pytest-cov to track test coverage. To generate a coverage report:

python -m pytest --cov=mastoscore --cov-report=html

This will create an HTML coverage report in the htmlcov/ directory. Open htmlcov/index.html in a web browser to see it.

Understanding Coverage Reports

The coverage report shows:

Improving Coverage

To improve test coverage:

  1. Identify uncovered code: Use the coverage report to find modules and functions with low coverage
  2. Write targeted tests: Create tests specifically for uncovered functions
  3. Test edge cases: Make sure your tests cover different branches of conditional statements
  4. Mock dependencies: Use mocking to test functions that depend on external services

Coverage Goals

For Mastoscore, aim for:

Excluding Code from Coverage

If code doesn't need to be tested or is difficult to test, exclude it from coverage reports using comments:

def difficult_to_test_function():
    try:
        # Some code that's hard to test
        pass
    except Exception:  # pragma: no cover
        # This exception handler won't be counted in coverage
        pass

Coverage Configuration

You can configure coverage settings in a .coveragerc file:

[run]
source = mastoscore
omit =
    */tests/*
    */site-packages/*

[report]
exclude_lines =
    pragma: no cover
    def __repr__
    raise NotImplementedError

This configuration: - Specifies that we only want to measure coverage for the mastoscore package - Omits test files and site-packages from coverage measurement - Excludes certain lines from coverage reporting