【发布时间】:2017-09-30 07:20:29
【问题描述】:
我正在编写各种测试。 他们中的大多数看起来像这样:
@pytest.mark.parametrize("name, price, count, type, countPoints, device", [
('test_name1', 3001, 1, 'key', 1, CAR),
('test_name2', 3000, 167, '', 1, MOTO),
# and so on, choosing different parameters
])
def test_getItemTradePreferences(name, price, count, type, countPoints, appid):
assert testing_funtion(price,count,type,countPoints,appid) == val_obj.getItemTradePreferences(name,price,count,type,countPoints)
然后我认为最好不要手动输入参数,而是编写一个使用随机的函数并为我做。
def generate_testing_values():
return ['test_nameX', randint(0, 3000), randint(1, 1000), '', randint(1, 1000), choice([CAR, MOTO])]
并像这样调用测试:
@pytest.mark.parametrize("name, price, count, type, countPoints, device", [
generate_testing_values(),
generate_testing_values(),
generate_testing_values(),
# can I call generate_testing_values() in loop?
])
def test_getItemTradePreferences(name, price, count, type, countPoints, appid):
assert testing_funtion(price,count,type,countPoints,appid) == val_obj.getItemTradePreferences(name,
price,
count,type,
countPoints)
但是我可以在装饰器中以某种方式调用这个 generate_testing_values() 循环吗? 我还没有找到解决办法,如果你知道请分享。
谢谢!
【问题讨论】:
-
你试过了吗?
标签: python loops testing decorator