Skip to content

Commit c1da74d

Browse files
committedMar 7, 2024
Catch and report correctly empty exceptions raised in subject method
1 parent fcf6b0e commit c1da74d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎src/unittest_extensions/case.py

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def result(self) -> Any:
5959
self._subjectResult = self.subject(**self._subjectKwargs)
6060
return self._subjectResult
6161
except Exception as e:
62+
if len(e.args) == 0:
63+
raise e
6264
msg = e.args[0]
6365
if "subject() got an unexpected keyword argument" in msg:
6466
raise TestError(

‎src/unittest_extensions/tests/test_use_case.py

+11
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,14 @@ def test_mutate_cached_result(self):
193193
self.assertResult([1, 2])
194194
self.cachedResult().append(3)
195195
self.assertListEqual(self.cachedResult(), [1, 2])
196+
197+
198+
class TestRaiseEmptyException(TestCase):
199+
class MyError(Exception):
200+
pass
201+
202+
def subject(self):
203+
raise self.MyError() # exception should be empty, i.e. no args
204+
205+
def test_reraises_empty_exception(self):
206+
self.assertResultRaises(self.MyError)

0 commit comments

Comments
 (0)
Please sign in to comment.