Код: Выделить всё
import unittest
from unittest.mock import patch, Mock, call
class MyTest(unittest.TestCase):
@patch(mymodule.DepObj)
def mytest(self, mock_obj):
mock_obj_ret = mock_obj.return_value # Object from constructor
# Call test method
callList = mock_obj_ret.method_calls
self.assertEqual(5, len(callList))
print(callList)
Код: Выделить всё
[call.mymethod0(), call.mymethod1(MYARG1, key=val), call.mymethod2(myarg1, myarg2), call.mymethod3(myarg3), ...]
Может быть что-то вроде этого:
Код: Выделить всё
self.assertEqual("mymethod2", callList[1].name) # Doesn't work
Код: Выделить всё
{'_mock_name': None, '_mock_parent': None, '_mock_from_kall': True}
Я могу получить аргументы и kwargs из одного вызова следующим образом:
Код: Выделить всё
print(mock_obj_ret.method_calls[1].args)
print(mock_obj_ret.method_calls[1].kwargs)
Подробнее здесь: https://stackoverflow.com/questions/773 ... -in-python