Skip to content

Commit

Permalink
Raise in cachedResult when result is not called
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxcode123 committed Feb 12, 2024
1 parent ada97bf commit 1e916f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/unittest_extensions/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ def result(self) -> Any:
def cachedResult(self) -> Any:
"""
Return the result of the last `subject` call.
Use this function if when you to assert different attributes of your
Use this function when you want to assert different attributes of your
subject without executing it multiple times.
Raises `unittest_extensions.TestError` if subject has not been called.
"""
if not hasattr(self, "_subject_result"):
raise TestError("Cannot call 'cachedResult' before calling 'result'")
return self._subject_result

def assertResult(self, value):
Expand Down
5 changes: 5 additions & 0 deletions src/unittest_extensions/tests/test_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def test_missing_arg_raises(self):
TestError, "Subject misses 1 required positional argument."
)

@args({"a": 1, "b": 2})
def test_cachedResult_raises(self):
with self.assertRaises(TestError):
self.cachedResult()


class TestAppend(TestCase):

Expand Down

0 comments on commit 1e916f2

Please sign in to comment.