Properly raise exception in test to set __traceback__
This ensure that there is no issues when trying to format the traceback
with IPython 8+ (still currently in alpha).
Closes (unless we also want to protect passing None values in
npe1)
@@ -17,12 +17,22 @@ def test_format_exceptions(cgitb, as_html, monkeypatch):
'standard_metadata',
lambda x: {'package': 'test-package', 'version': '0.1.0'},
)
- _ = PluginError(
+
+ # we make sure to actually raise the exceptions,
+ # otherwise they will miss the __traceback__ attributes.
+ try:
+ try:
+ raise ValueError('cause')
+ except ValueError as e:
+ raise PluginError(
'some error',
plugin_name='test_plugin',
plugin="mock",
- cause=ValueError("cause"),
+ cause=e,
)
+ except PluginError:
+ pass
+
formatted = exceptions.format_exceptions('test_plugin', as_html=as_html)
assert "some error" in formatted
assert "version: 0.1.0" in formatted
