Skip to content

Commit

Permalink
Add tests ensuring failed event serialization is handled correctly
Browse files Browse the repository at this point in the history
[CT-2264](#7113) states
that failed serialization should result in an exception handling path
which will fire another event instead of raising an exception. This is
hard to test perfectly because the exception handling path for
serialization depending on whether pytest is present. If pytest isn't
present, a new event documentation the failed serialization is fired.
If pytest is present, the failed serialization gets raised as an exception.
Thus this added test ensures that the expected exception is raised and
assumes that the correct event will be fired normally.
  • Loading branch information
QMalcolm committed Mar 31, 2023
1 parent b7f0caa commit 21e8ff1
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/unit/test_events.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import re
from typing import TypeVar

Expand Down Expand Up @@ -442,3 +443,21 @@ def test_date_serialization():
ti_dict = ti.to_dict()
assert ti_dict["started_at"].endswith("Z")
assert ti_dict["completed_at"].endswith("Z")


def test_bad_serialization():
"""Tests that bad serialization enters the proper exception handling
When pytest is in use the exception handling of `BaseEvent` raises an
exception. When pytest isn't present, it fires a Note event. Thus to test
that bad serializations are properly handled, the best we can do is test
that the exception handling path is used.
"""

with pytest.raises(Exception) as excinfo:
types.Note(param_event_doesnt_have="This should break")

assert (
str(excinfo.value)
== "[Note]: Unable to parse dict {'param_event_doesnt_have': 'This should break'}"
)

0 comments on commit 21e8ff1

Please sign in to comment.