0
我想测试我们的代码库中对请求重试的处理。为此我想定义一个spy
,它为同一个调用返回不同的值。我使用doublex和py.test对我的测试:在每个调用中设置一个返回不同值的doublex间谍
这是工作测试用例,单个调用:
import pytest
from doublex import Spy, assert_that, ANY_ARG, is_
@pytest.mark.unit
def test__me():
with Spy() as spy:
spy.foo(ANY_ARG).returns(10)
assert_that(spy.foo(), is_(10))
重试将做同样的电话进行(即具有相同参数),但会返回不同的值。这将是类似这样的事情(不工作):
import pytest
from doublex import Spy, assert_that, ANY_ARG, is_
@pytest.mark.unit
def test__me():
# TODO: how to setup a spy returning changing values, with fixed calling arguments?
with Spy() as spy:
spy.foo(ANY_ARG).returns(10)
spy.foo(ANY_ARG).returns(11)
# Each invocation will return a different value
assert_that(spy.foo(), is_(10))
assert_that(spy.foo(), is_(11))
我怎样才能设置返回每次调用不同的值是间谍吗?