Skip to content

Commit

Permalink
Add test for usage of saferepr
Browse files Browse the repository at this point in the history
  • Loading branch information
Anusha Shekhar authored and Anusha Shekhar committed Dec 13, 2023
1 parent 86a0b35 commit e7f6b98
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions testing/test_hookcaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pluggy import PluginValidationError
from pluggy._hooks import HookCaller
from pluggy._hooks import HookImpl
from pluggy._tracing import saferepr

hookspec = HookspecMarker("example")
hookimpl = HookimplMarker("example")
Expand Down Expand Up @@ -448,3 +449,21 @@ def conflict(self) -> None:
"Hook 'conflict' is already registered within namespace "
"<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>"
)

def test_hookcaller_repr_with_saferepr_failure(hc: HookCaller, addmeth: AddMeth) -> None:
@addmeth()
def he_method1() -> None:
pass

Check warning on line 456 in testing/test_hookcaller.py

View check run for this annotation

Codecov / codecov/patch

testing/test_hookcaller.py#L456

Added line #L456 was not covered by tests

@addmeth()
def he_method2() -> None:
# Intentional error to make the repr fail
raise ValueError("Intentional error in he_method2")

Check warning on line 461 in testing/test_hookcaller.py

View check run for this annotation

Codecov / codecov/patch

testing/test_hookcaller.py#L461

Added line #L461 was not covered by tests

@addmeth()
def he_method3() -> None:
pass

Check warning on line 465 in testing/test_hookcaller.py

View check run for this annotation

Codecov / codecov/patch

testing/test_hookcaller.py#L465

Added line #L465 was not covered by tests

# Verify that HookCaller.repr with saferepr still works despite the error
expected_repr = f"<HookCaller {saferepr(hc.name)}>"
assert repr(hc) == expected_repr

0 comments on commit e7f6b98

Please sign in to comment.