Hi first some code snippets:
module A:
class Foo:
def __init__(symbol):
self.last_price = None
def get_last_price(self):
x = do_some_query_requests()
self.last_price = x
module B:
class Bar:
def convert(symbol, amount):
curr = Foo(symbol)
curr.get_last_price()
#do some conversion with last_price
return converted_stuff
Should work fine. Now I try to test the convert method. But due the last price is changing, I thought about mocking the last_price property to check if the conversion works.
I found something about patches and Magic Mocks, but I don't know how to mock the output of a method of a class, which do not return something but only change internal properties.
Do somebody know how to do that? Maybe some other suggestions?
I thought about simply return the last_price, but some other methods are using it as well, so I don't need to call the function every time.
Thanks in Advance!