我想解开模拟方法的参数。我有一个被测试代码调用的模拟订阅者,我想验证 notify() 方法的调用。
class Subscriber:
def notify(self, event):
pass
我正在使用以下代码段来解压缩参数并验证两个调用:
calls= self.subscriber.notify.call_args_list
event1 = calls[0][0][0]
event2 = calls[1][0][0]
assert_that(event1, instance_of(CreatedEvent))
assert_that(event1.file.name, equal_to("foo.txt"))
但是解包事件的两行代码非常笨拙,并且与可读代码相差甚远。有人知道解开论点的更好方法吗?
非常感谢!