-
-
Notifications
You must be signed in to change notification settings - Fork 448
Lines incorrectly reporting as not covered when running with --branch #605
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
Comments
Thanks for the detailed instructions. I had to install a bunch of requirements (including enum34 manually, which isn't mentioned in any requirements file?). But then I did not see the results you see:
|
Hi, I was able to get probably the same bug with a minimal example with pytest: test_foo.py
(which more or less translates to Results:
As you can see, the first test was "covered" in full. The Also, I made another test - the same file with executing the test functions manually and without pytest at all:
Note that:
Coverage 4.5.1 (I had the same issue with 4.0, but with different result presentation pytest 3.5.0 |
@bluefish6 We should probably create this as a new bug, in case it is not the same cause as the original report here. But I tried running your code, and did not see the same results. pytest-cov didn't produce any reporting output:
When I run with coverage directly, I get 100% coverage:
The code I ran:
|
Hi, I was seeing similar behavior where lambdas being passed to a method were being reported as a missed arc in python 2.7.6, python 3.5.1 and python 3.6.0 (if that matters). In my case, changing the lambdas to the appropriate partial caused the coverage check to pass. Interestingly, in a chain of method calls in which two lambdas are passed, the same line (ie I don't have time right now but I'll take a closer look later today. |
@nedbat Thanks for taking a look! I'm terribly sorry - I mistakenly did not include the parameter
I was able to reproduce it also with:
I solved the mystery. The one to blame is pytest and it's "assertion rewrite hook". As far as I understand, it changes the code of all
Quick test - let's pretend that our system does not support the hook: (
And voilla, no branches uncovered. So to sum up - the bug is somewhere inside the assertion rewrite mechanism of pytest. I will open an issue there with link to this issue for reference. |
Issue created in pytest repo: pytest-dev/pytest#3689 |
Possibly my bug is a duplicate of #515 |
Sadly this 5 year old bug is still valid and probably it would worth even a runtime warning for those that make the mistake of enabling branch coverage. It has nothing to do with pytest, as I had the code below that also reports no branch coverage, even if I tested with the debugger to see that the loop really executes. if isinstance(when, list):
for item in when:
return _changed_in_when(item) |
@ssbarnea can you provide a complete example? |
I will to isolate it after I deal with current pile of incoming changes. You can see that mentioned disablement that increases total coverage ~4% by disabling branch coverage. I know that branch is good, but is good only when it works. I wonder how hard it will be to reproduce it in isolation, as we do use xdist and subprocess coverage commands too, I would not be surprised to discover that the issue happens only in conjunction with one of these. |
@ssbarnea I saw the same issue with branch, using In your case, you may be assuming |
Originally reported by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)
I ran into this problem when testing Hypothesis: Lines that are definitely covered by a test are showing up as uncovered in coverage.
The following is the test file:
When testing Hypothesis commit 8844ca758737a6439a82507e7910972c6fa22358 (bb), this shows lines 156-158 in src/hypothesis/searchstrategy/strategies.py as uncovered. However the lines are definitely covered by this test (see below for evidence).
To reproduce this problem:
(now copy the above example as test_local.py)
Salient features:
The text was updated successfully, but these errors were encountered: