小编Bew*_*ang的帖子

如何在@given 中参数化假设策略

我正在测试一个 REST API,它可以处理不同的请求,例如过时的和无日期的。一个请求有一个名为 的字段request_type。我想知道在假设中编写测试的最佳方法是什么:

我可以写两个睾丸,一个是dateed,一个是dateless。

但是对于一个共同的属性,我可以编写一个与pytest.mark.parametrize. 问题是请求策略如何req_type@given.

@pytest.mark.parameterize('req_type', ['dated', 'dateless'])
@given(req=requests())
def test_process_request(req, req_type):
   # override the parameter req_type in req with input req_type
   pass
Run Code Online (Sandbox Code Playgroud)

有没有办法参数化像@given(req=requests(req_type))?或者我应该随机生成带有日期和无日期的请求并通过测试?

python python-hypothesis

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

标签 统计

python ×1

python-hypothesis ×1