给出assert_any_call的文档
我有一个日志语句想要断言
...
logger.warning('Backup quantity is 0, supplied uuids %s, matched machines: %s', uuids, machines)
...
查看我的单元测试的最后 3 行(前 2 行仅用于调查目的)
# deliberate fail so it prints what it expects
logger.warning.assert_not_called()
# prints the params used in the official assert
print('Backup quantity is 0, supplied uuids %s, matched machines: %s', [vm3_uuid], VirtualMachine.objects.none())
# actual official assert
logger.warning.assert_any_call('Backup quantity is 0, supplied uuids %s, matched machines: %s', [vm3_uuid], VirtualMachine.objects.none())
测试的输出
assert_not_called
是:
AssertionError: Expected 'warning' to not have been called. Called 2 times.
Calls: [call('Backup quantity is 0, supplied uuids %s, matched machines: %s', ['232d7937-975c-457b-8a11-ac473d0e04a0'], <QuerySet []>),
call('%s %s cannot find proxmox UUID from BIS', 'DEF-456', 'vm4')]
参数打印是
Backup quantity is 0, supplied uuids %s, matched machines: %s ['232d7937-975c-457b-8a11-ac473d0e04a0'] <QuerySet []>
官方断言失败
AssertionError: warning('Backup quantity is 0, supplied uuids %s, matched machines: %s', ['232d7937-975c-457b-8a11-ac473d0e04a0'], <QuerySet []>) call not found
除非我错过了一些非常明显的东西,否则我不知道为什么
assert_any_call
会失败?
您拨打了
VirtualMachine.objects.none()
两次。这会产生两个不同的、不平等的物体。