Skip to content

Commit

Permalink
added change to Hook_Method behaviour so that exceptions are captured…
Browse files Browse the repository at this point in the history
… and raised (this was causing side effects in @print_boto3_class())
  • Loading branch information
DinisCruz committed Sep 8, 2024
1 parent e3c666e commit f03b856
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion osbot_utils/testing/Hook_Method.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@

class Hook_Method:

def __init__(self, target_module, target_method):
def __init__(self, target_module, target_method, raise_exception=True):
self.target_module = target_module
self.target_method = target_method
self.raise_exception = raise_exception # todo: figure out the impact of raising this by default
self.target = getattr(target_module, target_method)
self.wrapper_method = None
self.calls = []
self.on_before_call = []
self.on_after_call = []
self.mock_call = None


def __enter__(self):
self.wrap()
return self
Expand Down Expand Up @@ -107,6 +109,8 @@ def wrapper_method(*args, **kwargs):
'duration' : int(duration.seconds()*1000)
}
self.calls.append(call)
if self.raise_exception and exception:
raise exception
return call['return_value']

self.wrapper_method = wrapper_method
Expand Down

0 comments on commit f03b856

Please sign in to comment.