Skip to content

Commit e7f6b98

Browse files
Anusha ShekharAnusha Shekhar
authored andcommitted
Add test for usage of saferepr
1 parent 86a0b35 commit e7f6b98

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

testing/test_hookcaller.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pluggy import PluginValidationError
1212
from pluggy._hooks import HookCaller
1313
from pluggy._hooks import HookImpl
14+
from pluggy._tracing import saferepr
1415

1516
hookspec = HookspecMarker("example")
1617
hookimpl = HookimplMarker("example")
@@ -448,3 +449,21 @@ def conflict(self) -> None:
448449
"Hook 'conflict' is already registered within namespace "
449450
"<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>"
450451
)
452+
453+
def test_hookcaller_repr_with_saferepr_failure(hc: HookCaller, addmeth: AddMeth) -> None:
454+
@addmeth()
455+
def he_method1() -> None:
456+
pass
457+
458+
@addmeth()
459+
def he_method2() -> None:
460+
# Intentional error to make the repr fail
461+
raise ValueError("Intentional error in he_method2")
462+
463+
@addmeth()
464+
def he_method3() -> None:
465+
pass
466+
467+
# Verify that HookCaller.repr with saferepr still works despite the error
468+
expected_repr = f"<HookCaller {saferepr(hc.name)}>"
469+
assert repr(hc) == expected_repr

0 commit comments

Comments
 (0)