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

run command does not respect the --omit flag #218

Closed
nedbat opened this issue Nov 30, 2012 · 4 comments
Closed

run command does not respect the --omit flag #218

nedbat opened this issue Nov 30, 2012 · 4 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Nov 30, 2012

Originally reported by Jonathan Suever (Bitbucket: suever, GitHub: suever)


When running coverage and specifying a source directory, if you would like to omit a submodule using the --omit flag, it is ignored by run.

If you add the omit definition to a configuration file under the [run] section, it appears that it respects it, however, it doesn't actually it's just that both REPORT and HTML read the omit definition of the [run] part of the configuration file.

If you remove the configuration file, then don't actually run coverage again, but rather just generate a report, you can see that the "omitted" folder was still processed.

I have attached an example module along with a bash script for demonstrating the issue (reproduce.sh). In this example, I am attempting to ignore test_module/contrib.


@nedbat
Copy link
Owner Author

nedbat commented Dec 30, 2012

First, thanks for the great reproducible test case!

Here's the output I got:

##################################################
Running coverage without an OMIT flag
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       0      0   100%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         1      0   100%
--------------------------------------------------
TOTAL                              2      0   100%

##################################################
Running coverage with an OMIT flag
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       0      0   100%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         1      0   100%
--------------------------------------------------
TOTAL                              2      0   100%

##################################################
Creating .coveragerc file and specifying omit there
##################################################
.coveragerc contents:
[run]
omit=
	test_module/contrib/*

Name                         Stmts   Miss  Cover
------------------------------------------------
test_module/__init__             1      0   100%
test_module/test/__init__        0      0   100%
test_module/test/run_tests       1      0   100%
------------------------------------------------
TOTAL                            2      0   100%

##################################################
Now removing .coveragerc file
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       0      0   100%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         1      0   100%
--------------------------------------------------
TOTAL                              2      0   100%

Here's what's happening: test_module/contrib/init.py was never run. Because you specified source=test_module, when the execution was done, coverage.py searched the tree for unexecuted files, and found that file, and marked it as unexecuted in the results.

BUG: the search for unexecuted files should take the "omit" setting into account, and not add them as unexecuted if they are omitted.

I fiddled with the test case some, and added some more cases. I made test_module/contrib/init.py actually execute, and I added a run with no --source setting. I got this:

##################################################
Running coverage without an OMIT flag
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       1      0   100%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         2      0   100%
--------------------------------------------------
TOTAL                              4      0   100%

##################################################
Running coverage with an OMIT flag
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       1      1     0%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         2      0   100%
--------------------------------------------------
TOTAL                              4      1    75%

##################################################
Running coverage with an OMIT flag and no SOURCE
##################################################
Name                         Stmts   Miss  Cover
------------------------------------------------
test_module/__init__             1      0   100%
test_module/test/run_tests       2      0   100%
------------------------------------------------
TOTAL                            3      0   100%

##################################################
Creating .coveragerc file and specifying omit there
##################################################
.coveragerc contents:
[run]
omit=
	test_module/contrib/*

Name                         Stmts   Miss  Cover
------------------------------------------------
test_module/__init__             1      0   100%
test_module/test/__init__        0      0   100%
test_module/test/run_tests       2      0   100%
------------------------------------------------
TOTAL                            3      0   100%

##################################################
Now removing .coveragerc file
##################################################
Name                           Stmts   Miss  Cover
--------------------------------------------------
test_module/__init__               1      0   100%
test_module/contrib/__init__       1      1     0%
test_module/test/__init__          0      0   100%
test_module/test/run_tests         2      0   100%
--------------------------------------------------
TOTAL                              4      1    75%

Notice in the first case (no omit), the file is marked as 100%. In the second case (omit), it's marked as 0%! Keep in mind, the file is fully run. In this second case, it's because the actual execution is ignored because of the omit, but then the file is found during the search for unexecuted files, and added in as unexecuted.

In the third case (omit, but no source), the file is completed left out of the report, as you'd expect.

Thanks for the report, and sorry for the delay in digging into it!

@nedbat
Copy link
Owner Author

nedbat commented Dec 30, 2012

I'd like to fix this in the next release.

@nedbat
Copy link
Owner Author

nedbat commented Dec 30, 2012

Here's the modified test case I used.

@nedbat
Copy link
Owner Author

nedbat commented Apr 21, 2013

Fixed in changeset 4e67741540e2 (bb).

@nedbat nedbat closed this as completed Apr 21, 2013
@nedbat nedbat added minor bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant