-
Notifications
You must be signed in to change notification settings - Fork 586
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
Hypothesis Hijacking of Coverage Collector Breaks Coverage of Unexecuted Files #1085
Comments
|
Thanks for letting us know - this is a great bug report. 🎉 Based on a quick skim, any fix will require careful thought and testing to avoid breaking something else - there are some stateful parts in the way it clears saved data that could cause trouble. If you could provide a small example of code+tests with this problem, that would make debugging a lot easier and let us know whether a fix actually resolves the issue 😄 |
|
No worries, feel free to fork this into HypothesisWorks! |
|
Thanks for the great bug report seconded! I'll try to look at this in the next week or so. I think your suggested fix looks good, but the more I look at the original code the more I'm suspicious of what it's doing (I mean beyond the basics that it's an obvious awful hack), so this is going to require some care. |
|
Of course! Yeah I can't properly explain what my face looked like when I was looking at a function in |
😳 sorry. There's not really a good way to do what Hypothesis needs to do there right now, so I kinda just rammed it in. I have some open issues and an IOU to Ned to try and sort out a better API for this. |
|
Haha no worries at all, I definitely laughed, and I absolutely get working with what you have - if anything, I appreciate the honesty as it made more sense when debugging it as to where I was! Definitely appreciate the time and investment you all put into the library. |
|
The upstream issues for a better API are nedbat/coveragepy#603 and nedbat/coveragepy#604 - we're currently using internals, which is bad in principle and also harder in practice than a public API. Therefore, a good first contribution would be to ensure that the return value from hypothesis/hypothesis-python/src/hypothesis/core.py Lines 655 to 676 in 7e4ab71
(and pssst, @DRMacIver, any idea why the new save_data function replaces itself with the original version the first time it's called?) |
|
I have added a PR #1538 that has a test case for the coverage collector mistake, and also implements the simple solution proposed by @theaeolianmachine and @Zac-HD . Do we want to leave this issue open pending a more complete refactor? |
|
With the basic problem fixed and a regression test in place I'm happy to close this 😄 |
Hey Hypothesis contributors - thanks for contributing to such a useful library.
Recently we were really befuddled that after using coverage for a long time, it was no longer respecting the
--sourceflag, which searches for unexecuted Python files to include in the coverage report. For a team that's working up its code coverage, it's pretty essential to get a realistic picture of the code base.However, when you use hypothesis in any of the tests, it only reports on files that are hit by tests, over inflating this number. Note this is specifically with coverage + py.test + hypothesis. I spent a decent bit of time debugging this, and found the following:
In collector.py in coverage, the Collector class has a save_data method.
Of note is that this function returns
Falseif no activity has happened on any of its tracers, but returnsTrueotherwise.Hypothesis, in core.py has a hijack_collector function in StateForActualGivenExecution which adds on top of it. Of note is that this function does not return anything - it ignores the bool value returned from coverage's
Collector.save_data, and being Python,Noneis technically returned.Unfortunately, this breaks coverage's
Coverage.get_datafunction which relies on it here because this conditional statement never gets run:Because
self.collector.save_data, being overwritten by Hypothesis, doesn't return a bool, and instead returnsNone.I'm not sure what the best fix for hypothesis is, but a reasonable guess in
hijack_collectorwould be:However, given my time investment up to this point, I'll leave it to you all to figure out the best way to fix this.
Thanks! Let me know if you all have any questions.
The text was updated successfully, but these errors were encountered: