我无法在docs,google或此处的pytest中找到使用pytest测试回调的特定示例。我发现了这一点:使用Python unittest测试回调调用的正确方法是什么?; 但这是用于单元测试的。我猜想应该去看pytest的monkeypatch功能,但是我是自动化测试的新手,正在寻找一个例子。
def foo(callback):
callback('Buzz', 'Lightyear')
#--- pytest code ----
def test_foo():
foo(hello)
# how do I test that hello was called?
# how do I test that it was passed the expected arguments?
def hello(first, last):
return "hello %s %s" % first, last
先感谢您。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句