Consider we have this function under test located in the module.py
:
def f(a, b):
return (a - b) if a > b else 1 / 0
And, we have the following test case in the test_module.py
:
from unittest import TestCase
from module import f
class ModuleTestCase(TestCase):
def test_a_greater_than_b(self):
self.assertEqual(f(10, 5), 5)
If we run tests with pytest
with the enabled "branch coverage" with the HTML output reporting:
pytest test_module.py --cov=. --cov-branch --cov-report html
The report is going to claim 100% branch coverage with all the "partial" branches covered:
But, we clearly have not covered the else 1 / 0
part at all.
Is there a way to improve reporting to see the non-covered parts of the ternary operators?
Aucun commentaire:
Enregistrer un commentaire