-
-
Notifications
You must be signed in to change notification settings - Fork 432
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
Coverage not showing coverage for continue after assert #1029
Comments
Actually, if you put any kind of no-op between the assert and continue like a
Presumably anything that gets optimized away by the bytecode compiler doesn't work. The simplest workaround I found is to put a name there, like assert i == 1
i
continue since that triggers a namespace lookup. |
This looks like a duplicate of #198? |
It definitely looks similar. You'd have to make the call on whether it's the same because I don't know the technical details. My understanding there is that the optimizer optimizes out the def test():
for i in range(10):
if i == 1:
assert i == 1
continue
print(i)
test() still exhibits the problem. The bytecode seems similar enough with and without the |
yeah the the primary difference is instruction >>> def test():
... for i in range(10):
... if i == 1:
... assert i == 1
... continue
...
>>> def test2():
... for i in range(10):
... if i == 1:
... assert i == 1
... i
... continue
...
>>> import dis
>>> dis.dis(test)
2 0 LOAD_GLOBAL 0 (range)
2 LOAD_CONST 1 (10)
4 CALL_FUNCTION 1
6 GET_ITER
>> 8 FOR_ITER 26 (to 36)
10 STORE_FAST 0 (i)
3 12 LOAD_FAST 0 (i)
14 LOAD_CONST 2 (1)
16 COMPARE_OP 2 (==)
18 POP_JUMP_IF_FALSE 8
4 20 LOAD_FAST 0 (i)
22 LOAD_CONST 2 (1)
24 COMPARE_OP 2 (==)
26 POP_JUMP_IF_TRUE 8
28 LOAD_GLOBAL 1 (AssertionError)
30 RAISE_VARARGS 1
5 32 JUMP_ABSOLUTE 8
34 JUMP_ABSOLUTE 8
>> 36 LOAD_CONST 0 (None)
38 RETURN_VALUE
>>> dis.dis(test2)
2 0 LOAD_GLOBAL 0 (range)
2 LOAD_CONST 1 (10)
4 CALL_FUNCTION 1
6 GET_ITER
>> 8 FOR_ITER 30 (to 40)
10 STORE_FAST 0 (i)
3 12 LOAD_FAST 0 (i)
14 LOAD_CONST 2 (1)
16 COMPARE_OP 2 (==)
18 POP_JUMP_IF_FALSE 8
4 20 LOAD_FAST 0 (i)
22 LOAD_CONST 2 (1)
24 COMPARE_OP 2 (==)
26 POP_JUMP_IF_TRUE 32
28 LOAD_GLOBAL 1 (AssertionError)
30 RAISE_VARARGS 1
5 >> 32 LOAD_FAST 0 (i)
34 POP_TOP
6 36 JUMP_ABSOLUTE 8
38 JUMP_ABSOLUTE 8
>> 40 LOAD_CONST 0 (None)
42 RETURN_VALUE |
Describe the bug
A clear and concise description of the bug.
Example script
It thinks the
continue
line is not covered. If I remove the assert, or put something likeprint("Covered")
between theassert
andcontinue
, it works.To Reproduce
Python 3.8.5 and Coverage 5.2.1
The text was updated successfully, but these errors were encountered: