我正在写各种各样的测试。 其中大部分都是这样的:
@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)
但是我可以在decorator中的循环中调用generate\u testing\u values()吗? 我还没有找到解决办法,如果你知道请分享。你知道吗
谢谢你!你知道吗
也许您应该构建generate \u testing \u values()函数来同时返回所有值。你知道吗
相关问题 更多 >
编程相关推荐