Skip to content

Commit

Permalink
fix error on exception handling during emit/slots.__call__
Browse files Browse the repository at this point in the history
new test for exception handling during emit/slots.__call__
enable pytest log on console
  • Loading branch information
gnzsnz committed Sep 1, 2024
1 parent 0851e26 commit 2bca019
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eventkit/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __call__(self, caller, *args, **kwargs):
if len(caller.error_event):
caller.error_event.emit(caller, error)
else:
Event.logger.exception(
caller.logger.exception(
f"Value {args} caused exception for event {caller}"
)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ ignore = [
[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "session"
asyncio_mode = "auto"
log_cli = true
16 changes: 16 additions & 0 deletions tests/slots_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,19 @@ def test_slots_call_exception_func(self):
# on error obj.value not set
assert not hasattr(obj, "value")
assert obj3.value == 42

def test_slots_call_exception_logger(self):
"""Test Slots.__call__ with exception and Event.logger"""
slots = Slots()

event = Event("test_slots_call_exception_logger")
obj = Obj()
obj2 = Obj()
slots.add(None, None, func) # success
slots.add(obj2.method, None, None) # success
slots.add(None, None, error_func) # fail
#
slots(event)
# on error obj.value not set
assert not hasattr(obj, "value")
assert obj2.value == 42

0 comments on commit 2bca019

Please sign in to comment.