mock_calls
mock_calls
records all calls to the mock object, its methods, magic methods and return value mocks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | >>> mock = MagicMock() >>> result = mock(1, 2, 3) >>> mock.first(a=3) <MagicMock name= 'mock.first()' id= '...' > >>> mock.second() <MagicMock name= 'mock.second()' id= '...' > >>> int(mock) 1 >>> result(1) <MagicMock name= 'mock()()' id= '...' > >>> expected = [call(1, 2, 3), call.first(a=3), call.second(), ... call.__int__(), call()(1)] >>> mock.mock_calls == expected True |
Members of mock_calls
are call
objects. These can be unpacked as tuples to get at the individual arguments. See calls as tuples.
Please login to continue.