0
私は様々なテストを書いています。 およびそれらのほとんどは次のようになります。 デコレータ内でテスト用のパラメータをランダム化するコール関数
@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()を呼び出すことができますか? 私は解決策をまだ見つけられていません。
ありがとうございました!
試しましたか? – Sraw