File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,8 @@ def result(self) -> Any:
4343 decorator.
4444 """
4545 try :
46- return self .subject (** self ._subjectKwargs )
46+ self ._subject_result = self .subject (** self ._subjectKwargs )
47+ return self ._subject_result
4748 except TypeError as e :
4849 msg = e .args [0 ]
4950 if "unexpected keyword argument" in msg :
@@ -60,6 +61,14 @@ def result(self) -> Any:
6061 )
6162 raise e
6263
64+ def cachedResult (self ) -> Any :
65+ """
66+ Return the result of the last `subject` call.
67+ Use this function if when you to assert different attributes of your
68+ subject without executing it multiple times.
69+ """
70+ return self ._subject_result
71+
6372 def assertResult (self , value ):
6473 """
6574 Fail if the result is unequal to the value as determined by the '=='
Original file line number Diff line number Diff line change @@ -123,3 +123,15 @@ def test_change_state(self):
123123 def test_change_state_twice (self ):
124124 self .assertResult (2 )
125125 self .assertResult (3 )
126+
127+ def test_change_state_cached_result (self ):
128+ self .result ()
129+ self .assertEqual (self .cachedResult (), 2 )
130+ self .result ()
131+ self .assertEqual (self .cachedResult (), 3 )
132+
133+ def test_manually_change_state_cached_result (self ):
134+ self .result ()
135+ self .assertEqual (self .cachedResult (), 2 )
136+ self .instance .state_var += 1
137+ self .assertEqual (self .cachedResult (), 2 )
You can’t perform that action at this time.
0 commit comments