
У меня есть оператор журнала, который я хочу проверить
Код: Выделить всё
...
logger.warning('Backup quantity is 0, supplied uuids %s, matched machines: %s', uuids, machines)
...
Код: Выделить всё
# 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())
Код: Выделить всё
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'], ),
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']
Код: Выделить всё
AssertionError: warning('Backup quantity is 0, supplied uuids %s, matched machines: %s', ['232d7937-975c-457b-8a11-ac473d0e04a0'], ) call not found
Подробнее здесь: https://stackoverflow.com/questions/792 ... t-matching
Мобильная версия