pytest-cov
pytest-cov copied to clipboard
condition was never false
Summary
The target function is below.(This is code that occurs the issue.)
def main(value):
result = None
try:
try:
result = 1 / value
finally:
if result is not None:
print(result)
except ZeroDivisionError as ex:
print(ex)
The test function is below.
import pytest
from target import main
@pytest.mark.parametrize('value', [
1,
0,
])
def test(value):
main(value)
Expected vs actual result
- Expected
- I want complete branch coverage on line 7.
- actual
-
line 7 didn't return from function 'main', because the condition on line 7 was never false
-
line 7 didn't return from function 'main', because the condition on line 7 was always true
(5.0.0)
-
Reproducer
Versions
title | value |
---|---|
Python | 3.9.18 |
Platform | Linux-5.4.0-181-generic-x86_64-with-glibc2.31 |
Packages | pytest: 7.4.2 |
pluggy: 1.3.0 | |
Plugins | html: 4.0.2 |
cov: 4.1.0 | |
metadata: 3.0.0 | |
mock: 3.12.0 | |
only: 2.0.0 |
Config
not use.
What has been tried to solve the problem
Add dummy code to line 9.