Specifying source files





You can specify source to measure with the --source command-line switch, or the [run] source configuration value. The value is a comma- or newline-separated list of directories or package names. If specified, only source inside these directories or packages will be measured. Specifying the source option also enables coverage.py to report on unexecuted files, since it can search the source tree for files that haven’t been measured at all. Only importable files (ones at the root of the tree, or in directories with a __init__.py file) will be considered. Files with unusual punctuation in their names will be skipped (they are assumed to be scratch files written by text editors). Files that do not end with .py or .pyo or .pyc will also be skipped.

You can further fine-tune coverage.py’s attention with the --include and --omit switches (or [run] include and [run] omit configuration values). --include is a list of file name patterns. If specified, only files matching those patterns will be measured. --omit is also a list of file name patterns, specifying files not to measure. If both include and omit are specified, first the set of files is reduced to only those that match the include patterns, then any files that match the omit pattern are removed from the set.


omit =
    # omit anything in a .local directory anywhere
    # omit everything in /usr
    # omit this single file


If both source and include are set, the include value is ignored and a warning is printed on the standard output.



The report commands (report, html, annotate, and xml) all take optional modules arguments, and --include and --omit switches. The modules arguments specify particular modules to report on. The include and omit values are lists of file name patterns, just as with the run command.


Note that these are ways of specifying files to measure. You can also exclude individual source lines. See Excluding code from coverage.py for details.