How to test the following decorator which calls 3rd party library?
import third_party_lib
import functools
class MyDecorator:
def __init__(self, ....):
self.third_party_lib = ThirdPartyLib(....) # will create a 3rd party instance
def __call__(self, ...):
def decorator(f):
@functools.wraps(f)
def wrap(*arg, **kwargs):
result = f(*arg, **kwargs)
# ....
a = self.third_party_lib.send(value=result).get()
# ....
return result
return wrap
return decorator
I need to create an unit test to assert third_party_lib.send()
is called if a function is decorated by the decorator. And ideally, also assure the result of the test function is passed to the function.
decorator = MyDecorator(....)
@decorator(....)
def test_func():
ret = ...
return ret # ret should be passed to `third_party_lib.send()`