Skip to content

Commit 9417809

Browse files
committed
test(utils): Add test for safe_str and safe_repr when fail
Fixes GH-3515
1 parent 915b7af commit 9417809

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

tests/test_utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,17 @@ def test_get_error_message(error, expected_result):
646646
assert get_error_message(exc_value) == expected_result(exc_value)
647647

648648

649+
def test_safe_str_fails():
650+
class ExplodingStr:
651+
def __str__(self):
652+
raise Exception
653+
654+
obj = ExplodingStr()
655+
result = safe_str(obj)
656+
657+
assert result == repr(obj)
658+
659+
649660
def test_installed_modules():
650661
try:
651662
from importlib.metadata import distributions, version

tests/utils/test_general.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ def test_safe_repr_regressions():
3939
assert "лошадь" in safe_repr("лошадь")
4040

4141

42+
def test_safe_repr_fails():
43+
class ExplodingRepr:
44+
def __repr__(self):
45+
raise Exception
46+
47+
obj = ExplodingRepr()
48+
result = safe_repr(obj)
49+
50+
assert result == "<broken repr>"
51+
52+
4253
@pytest.mark.parametrize("prefix", ("", "abcd", "лошадь"))
4354
@pytest.mark.parametrize("character", "\x00\x07\x1b\n")
4455
def test_safe_repr_non_printable(prefix, character):

0 commit comments

Comments
 (0)