You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In for loop, when there is a condition ending with False (directly or evaluated from function) and then there is just continue in the indented block, this line is not recognized as hit. In the example below, if you uncomment the print function, coverage hit 100%. Tests pas with 100% also when continue directly behind : (not separate line).
Reproducer
Run pytest --cov --cov-report term-missing --cov-fail-under 100 with code snippet bellow.
CLI output
pytest --cov --cov-report term-missing --cov-fail-under 100
=========================================================================================================================== test session starts ============================================================================================================================
platform linux -- Python 3.8.16, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/tomasman/work/coverage_test
plugins: anyio-3.6.2, Faker-15.3.4, requests-mock-1.9.3, lazy-fixture-0.6.3, asyncio-0.16.0, cov-4.0.0
collected 1 item
test_foo.py . [100%]
---------- coverage: platform linux, python 3.8.16-final-0 -----------
Name Stmts Miss Cover Missing
-------------------------------------------
foo.py 5 1 80% 5
test_foo.py 8 0 100%
-------------------------------------------
TOTAL 13 1 92%
FAIL Required test coverage of 100% not reached. Total coverage: 92.31%
Code
# code in file foo.pydeffoo(A, B):
foriinA:
ifiinBorFalse:
# print("hit")continuereturnTrue
# code in file test_foo.pyfromfooimportfoodeftest_foo():
# hit 'continue' 4 timesA= [1, 2, 3, 4]
B= [1, 2, 3, 4]
assertfoo(A, B)
# never hit continueA= [1, 2, 3, 4]
B= [5]
assertfoo(A, B)
The text was updated successfully, but these errors were encountered:
Summary
In
for
loop, when there is a condition ending withFalse
(directly or evaluated from function) and then there is justcontinue
in the indented block, this line is not recognized as hit. In the example below, if you uncomment the print function, coverage hit 100%. Tests pas with 100% also whencontinue
directly behind:
(not separate line).Reproducer
Run
pytest --cov --cov-report term-missing --cov-fail-under 100
with code snippet bellow.CLI output
Code
The text was updated successfully, but these errors were encountered: