Skip to content

Commit

Permalink
more elaborate error msg + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ejgroene committed Nov 13, 2024
1 parent 781c9a9 commit b8d2f15
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions selftest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import sys # fiddling with stdout/err
import os # fiddling with stdout/err file descriptors
import io # StringIO for testing
import traceback # formating traceback for raises()


from .utils import asyncio_filtering_exception_handler, ensure_async_generator_func
Expand Down Expand Up @@ -230,7 +231,7 @@ def raises(exception=Exception, message=None):
defer.set_exception(e)
except BaseException as e:
raise AssertionError(
f"should raise {exception.__name__} but raised {type(e).__name__}"
f"should raise {exception.__name__} but raised:\n{''.join(traceback.format_exception(e))}"
).with_traceback(e.__traceback__) from e
else:
e = AssertionError(f"should raise {exception.__name__}")
Expand Down Expand Up @@ -646,7 +647,9 @@ def assert_raises_specific_exception():
with self_test.raises(KeyError):
raise RuntimeError("oops")
except AssertionError as e:
assert "should raise KeyError but raised RuntimeError" == str(e), str(e)
m = str(e)
assert m.startswith("should raise KeyError but raised:\nTraceback "), m
assert m.endswith('raise RuntimeError("oops")\nRuntimeError: oops\n'), repr(m)
try:
with self_test.raises(KeyError):
pass
Expand Down

0 comments on commit b8d2f15

Please sign in to comment.