-
Notifications
You must be signed in to change notification settings - Fork 213
Confusing behaviour with any(…) and a generator #310
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 report! |
For extra bonus funsies: the following code also gets a complaint about a missing branch from basket = ["apple", "banana", "cherry"]
def test_basket_contains_b():
assert any([
"b" in fruit for fruit in basket
]) |
Must be the assertion rewriter adding something that looks like a branch. The way I see it you're missing a test for empty basket :) |
@ionelmc My fruit basket is never empty. ;) |
Ran into this just now on debian 4.19.37, python3.6, running in a fresh virtualenv via nox, with Minimal reproducible example
|
This is not specific to pytest-cov. Given t_any.py: from collections import namedtuple
def test():
Element = namedtuple("Element", ["key", "val"])
elements = [
Element("squid", "teuthida"),
Element("clam", "tridacna"),
Element("whelk", "buccinoidea")
]
squid = next(e.val for e in elements if e.key == "squid")
if __name__ == "__main__":
test()
With
Line 15 is the last one - the call to the test function when not using pytest. |
Going through duplicates in coveragepy's issues I've landed at nedbat/coveragepy#515. But using So it's really an issue with coverage.py. (Coverage.py, version 4.5.2 with C extension, This is pytest version 4.3.0, Python 3.7.4 - apparently an old venv I have there for pytest-cov ;)) |
/cc @nedbat |
Consider the following example test:
If I run this test under pytest-cov, and print a report, it tells me that
8->exit
isn’t covered:If I wrap the generator comprehension in a list, coverage is happy:
If I run the body of that function under plain coverage, it doesn't complain, so it looks like this is something to do with the interactions with py.test?
I'm not sure if this is a bug per se, and it's not blocking my work – I can wrap my
any(…)
calls with a list – but it was confusing, and I thought it worth flagging the discrepancy between vanilla coverage and pytest-cov.Setup
Python 3.7.2 running on macOS. pytest-cov 2.7.1. I'm running in a fresh virtualenv with these dependencies:
Duplicates
I tried to look for existing bug reports, but "any" is such a common keyword I couldn't find anything useful.
The text was updated successfully, but these errors were encountered: