Skip to content

Using --include to also report on un-executed files or filter out files from --source #1928

Open
@BurnzZ

Description

@BurnzZ

Is your feature request related to a problem? Please describe.

Using --include to also report on un-executed files. Here's a use case:

foo.py:

def foo():
    return "bar"

test.py:

from foo import foo

def test_foo():
    assert foo() == "bar"

if __name__ == "__main__":
    test_foo()

untested.py:

def not_tested_nor_imported():
    return "untested"

Running coverage run test.py && coverage report results in:

Name      Stmts   Miss  Cover
-----------------------------
foo.py        2      0   100%
test.py       5      0   100%
-----------------------------
TOTAL         7      0   100%

Running coverage run --source=. test.py && coverage report results in:

Name          Stmts   Miss  Cover
---------------------------------
foo.py            2      0   100%
test.py           5      0   100%
untested.py       2      2     0%
---------------------------------
TOTAL             9      2    78%

So far so good! ✅ We can force the untested files to be in the report as per the docs:

Specifying the source option also enables coverage.py to report on un-executed files, since it can search the source tree for files that haven’t been measured at all.

However, using --include to force specific files coverage run --include="foo.py,untested.py" test.py && coverage report still omits the untested.py file.

Name     Stmts   Miss  Cover
----------------------------
foo.py       2      0   100%
----------------------------
TOTAL        2      0   100%

Describe the solution you'd like

It'd be great if we can use --include to also get coverage reports on specific files.

Describe alternatives you've considered

Perhaps we can use --include to filter out the files in --source, as the current behavior currently ignores --include:

--include is ignored because --source is set (include-ignored)

One workaround is to use --omit to exclude some files from --source which can give you files for --include. However, certain cases makes this hard (e.g. large code base being tested but you only want to --include a couple of files).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions