Skip to content

Commit 1e916f2

Browse files
committedFeb 12, 2024
Raise in cachedResult when result is not called
1 parent ada97bf commit 1e916f2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎src/unittest_extensions/case.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ def result(self) -> Any:
6464
def cachedResult(self) -> Any:
6565
"""
6666
Return the result of the last `subject` call.
67-
Use this function if when you to assert different attributes of your
67+
Use this function when you want to assert different attributes of your
6868
subject without executing it multiple times.
69+
70+
Raises `unittest_extensions.TestError` if subject has not been called.
6971
"""
72+
if not hasattr(self, "_subject_result"):
73+
raise TestError("Cannot call 'cachedResult' before calling 'result'")
7074
return self._subject_result
7175

7276
def assertResult(self, value):

‎src/unittest_extensions/tests/test_use_case.py

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def test_missing_arg_raises(self):
6262
TestError, "Subject misses 1 required positional argument."
6363
)
6464

65+
@args({"a": 1, "b": 2})
66+
def test_cachedResult_raises(self):
67+
with self.assertRaises(TestError):
68+
self.cachedResult()
69+
6570

6671
class TestAppend(TestCase):
6772

0 commit comments

Comments
 (0)
Please sign in to comment.