Mock, call_args_list, , .
, calculate_something .
calculate_something = Mock(return_value=None)
my_function :
calculate_something.call_args_list
( ).
Edit:
(, , Python3.3 )
mymodule.py
class Thing:
...
def calculate_something:
...
def my_function(things):
xs = [t.x for t in things]
x_calc = calculate_something(xs)
ys = [t.y for t in things]
y_calc = calculate_something(ys)
return True
test_file.py
import unittest
from unittest.mock import patch, call
import mymodule
class TestFoo(unittest.TestCase):
@patch('mymodule.calculate_something')
def test_mock(self, mock_calculate):
things = [mymodule.Thing(3, 4), mymodule.Thing(7, 8)]
mymodule.my_function(things)
callresult = mock_calculate.call_args_list
xargs = call([3, 7])
yargs = call([4, 8])
self.assertEqual(callresult, [xargs, yargs])
xargs, _ = callresult[0]
yargs, _ = callresult[1]
xexpected = [3, 7]
yexpected = [4, 8]
self.assertEqual(xargs[0], xexpected)
self.assertEqual(yargs[0], yexpected)
if __name__ == '__main__':
unittest.main()