将mock的call()对象与 一起使用时assert_has_calls,我很难断言已使用给定字符串并在末尾附加了未知值。
例如:
被测代码:
mystring = 'a known string with an unknown value: {0}'.format(unknown_value)
method_to_call(mystring)
Run Code Online (Sandbox Code Playgroud)
当前测试代码:
with mock.patch('method_to_call') as mocked_method:
calls = [call('a known string with and unknown value: {0}'.format(mock.ANY)]
call_method()
mocked_method.assert_has_calls(calls)
Run Code Online (Sandbox Code Playgroud)
这给了我一些类似的东西:
AssertionError: Calls not found.
Expected: [call('a known string with and unknown value: <ANY>')]
Run Code Online (Sandbox Code Playgroud)
如何断言给定的字符串已传递给方法但允许未知值?