小编Cia*_*ans的帖子

当我断言一个方法被调用时,如何通配一个字符串?Python3 模拟

mockcall()对象与 一起使用时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)

如何断言给定的字符串已传递给方法但允许未知值?

unit-testing assert wildcard mocking python-3.x

1
推荐指数
1
解决办法
934
查看次数

标签 统计

assert ×1

mocking ×1

python-3.x ×1

unit-testing ×1

wildcard ×1