Coverage for tests/common/test_assert_rewrite.py: 100%

15 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 19:49 +0000

1import pytest 

2 

3from utils import BaseTestClass 

4# the modules, not their classes: a class imported here with a name that starts with Test would be collected as a test 

5import utils.gen_utils as helpers_of_the_tests 

6import tests.utils.gen_utils as helpers_of_conftest 

7 

8 

9@pytest.mark.unit 

10class TestAssertRewrite(BaseTestClass): 

11 """The asserts of the helpers of tests/utils show their values when they fail, as the ones of the tests: conftest.py has pytest 

12 rewrite them. Without it, a failed assert of a helper is a bare AssertionError, with only its message if it has one.""" 

13 

14 #region Tests 

15 

16 # A helper imported as the tests import it, from utils 

17 def test_helpers_of_the_tests_show_the_values_of_a_failed_assert(self) -> None: 

18 with pytest.raises(AssertionError) as exc_info: 

19 helpers_of_the_tests.GenUtils.test_unsigned_big_integer(-5) 

20 # its message, and the comparison with the value that failed it, which only a rewritten assert has 

21 assert "Value cannot be negative" in str(exc_info.value) 

22 assert "assert -5 >= 0" in str(exc_info.value) 

23 

24 # The same helper imported as conftest.py imports it, from tests.utils 

25 def test_helpers_of_conftest_show_the_values_of_a_failed_assert(self) -> None: 

26 with pytest.raises(AssertionError) as exc_info: 

27 helpers_of_conftest.GenUtils.test_unsigned_big_integer(-5) 

28 assert "assert -5 >= 0" in str(exc_info.value) 

29 

30 #endregion