Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BurnzZ opened this issue Feb 11, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@BurnzZ
Copy link

BurnzZ commented Feb 11, 2025

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).

@BurnzZ BurnzZ added the enhancement New feature or request label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant