-
Notifications
You must be signed in to change notification settings - Fork 211
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
Code block reported missing when provably covered #167
Comments
Are subprocesses or multiprocess involved? I'm not sure what to make of this. Try disabling branch coverage. |
No subprocesses or multiprocess. All unit tests are single threaded unless pytest is multithreaded. Turned off branch coverage (removed --cov-branch) and it seems to be working correctly now. |
I would like to have branch coverage active, so if you want to point me at the pytest-cov code to start at, then can work through it to see if an error pops out. If one does, then a simple test can be generated to demonstrate then fix it. |
You're probably not running all the branches (you got no test where rules are all True). See https://coverage.readthedocs.io/en/coverage-4.4.1/branch.html I don't see how this is a problem with coverage or pytest-cov (a mere wrapper around coverage) ... |
As shown in the output text, when all (same) is True, the function _error() is not called. When it is not true, then it is called and you get a message about reservoirs and nodes with a list of the checks done for sameness and whether or not the individual item was true or false. Since this is the only block that generates this message (you do not have all 10000 lines of code so there is some trust here) then we can say from the output that both parts of the branch are exercised. Therefore, logic dictates that pytest-cov declaring it as missing is incorrect. I tried calling it an odd number of times as well as even. I changed the order to make the positive test first then the negative test first. Tried a bunch of silly things to diagnose further but they all resulted in the same missing block. |
In terms of your docs It seems that pytest-cov might be interpreting the How can that be true? First, |
Quick test shows that your documentation is correct. This code block produces same result:
This code block produces the expected coverage (136-143 are not missing):
All three cases should produce the same results as they are exactly the same behavior (minus some output to the terminal) with respect to branching. At least there is a tremendously simple test case that shows the problem. |
Coverage is a different project, those aren't my docs. I don't maintain them and I don't know the internals or particulars of branch coverage. Perhaps you should take this to it's bug tracker: https://bitbucket.org/ned/coveragepy/issues?status=new&status=open |
Sorry, but I am getting confused...
With those bullets, are you saying that this is the wrong forum and that I should take this to specified bitbucket? If this is the wrong forum, then, for my education, what is the relationship between pytest-cov and coverage.py? |
Hmmm, it (branch detection) seems to have problems with recursion as well... I have a recursive function that where I changed the |
pytest-cov uses coverage.py and only does pytest command line integration, and supports xdist/subprocesses/multiprocessing out of the box (with bare coverage.py it's very hard to get those right). It's not that it's the wrong forum, feel free to ping Ned right here, I don't mind. It's just that your bug report assumes that your tests can't be wrong and that I should know what's wrong without seeing a reproducer. See http://sscce.org/ |
Fair enough. Let me do a quick small test where I can post the whole unit and then ping Ned. |
Here is the test. It is not at all what I thought! Someone should let Ned know to look at it (I did not find him in the watchers list or let me know and I will try submitting to bitbucket): I used the same Here is my command line: Here is my result:
Here is the code being tested:
Sorry if it is more than you wanted, but I was trying to be complete. |
In hindsight now I think it's best to log a bug report in coverage's bugtracker (maybe bug is already there). |
I already looked through the open tickets and did not see it. I will log the ticket there. Just a shame to go through the whole explanation again. Thanks for your help. It has been a pleasure. |
This is a limitation of Python's: it optimizes away jumps to jumps, and you cannot disable the optimization. |
Since converage.py already supports pragma for code exclusion, would it be possible to add pragmas for inclusion? For instance, 'pragma cov-if' or 'pragma cov-for' etc to circumvent the optimization limitations. |
@ionelmc This should probably be closed as it's an upstream issue nedbat/coveragepy#594 (along with the duplicate nedbat/coveragepy#198) are closed now. |
It appears as though code covered with pytest is being reported as missing. While it may be a bug in pytest-cov, it may also be a problem with configuration. The configuration is quite simple and is all on the command line -- configuration files are avoided.
Here are the platform details:
If I then run the unit tests, it completes without error and the line that concerns me is:
The block of code 136-143 is:
This block is covered with same.values() all being true and with some false elements. This can be shown by forcing pytest with assert to fail and looking at the output:
While the messages is bit to consume all at once, the important bit is to notice that the block being reported as missing is generating the fail message. I included the good messages to show that they same block is called when
all (same.values())
is both True and False.Hence, I think this shows that the block is being reported as missing when it is provably being executed. I cannot post all of the code for someone in this group to test, but with some help I am willing to work through the pytest-cov code to help find and isolate the problem (looking for hints as how and where to start). With the best of luck someone will recognize that I did not type my command line correctly.
The text was updated successfully, but these errors were encountered: