coverage.py: exclude files

Viewed 31344

How do I exclude entire files from coverage.py reports?

According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd party libraries. Am I missing something? Can it be done?

5 Answers

In addition to the options in the other answers, you can also configure the ignored files via setup.cfg:

[coverage:run]
omit =
    some/directory/*
    debug_*.py

See the documentation for details.

Create a new file .coveragerc and add the following lines

[run]
branch = True
omit =
    directory/*

With pyproject.toml

[tool.coverage.run]
omit = [
    "some/directory/*",
    "other/lib.py"
]
Related