1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| from unittest.mock import Mock, call
mock = Mock()
mock.method(1, 2, key='value')
# 호출 여부
mock.method.assert_called()
mock.method.assert_called_once()
# 특정 인자로 호출되었는지
mock.method.assert_called_with(1, 2, key='value')
mock.method.assert_called_once_with(1, 2, key='value')
# 호출 횟수
print(mock.method.call_count) # 1
# 호출 기록
print(mock.method.call_args) # call(1, 2, key='value')
print(mock.method.call_args_list) # [call(1, 2, key='value')]
# 여러 호출 확인
mock.method(1)
mock.method(2)
mock.method.assert_has_calls([call(1), call(2)])
|