I am in proccess of writing variety of tests. and most of them are look like this:
@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)
then I thought it will be better not to type parameters manually but write a function which will use random and do it for me.
def generate_testing_values():
return ['test_nameX', randint(0, 3000), randint(1, 1000), '', randint(1, 1000), choice([CAR, MOTO])]
and call test like this:
@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)
But can I somehow call this generate_testing_values() in loop within decorator? I have not found the solution yet, if you know please share.
Thank you!
Aucun commentaire:
Enregistrer un commentaire