I am working with the following code and test, which live in separate files:
#exchange.py
def on_indicative_price_volume(self, msg):
symbol = self.get_symbol(msg.security_id)
breakpoint()
price = msg.pre_open_price * symbol.deal_price_multiplier
self.write_auc(msg.security_id)
#test.py
@mock.patch('exchange.IceExchange.get_symbol')
def test_indicative_price_and_vol(mock_symbol, exchange):
mock_symbol.deal_price_multiplier = 25
So in my unit test, I have mocked out the functionget_symbol
. So that when I print symbol
where I set the breakpoint
above, I get:
<MagicMock name='get_symbol().deal_price_multiplier.__rmul__()' id='14032624'>
So it has been mocked as expected. But now I want to set symbol.deal_price_multiplier
in my function to return the value 25.
As you can see above in my unit test I tried to do mock_symbol.deal_price_multiplier = 25
, but when I print symbol.deal_price_multiplier
in my function I then get:
<MagicMock name='get_symbol().deal_price_multiplier.__rmul__()' id='14424'>
Which is not what I want, I want mock_symbol.deal_price_multiplier
to simply return 25. How can I do this?