1

我正在尝试自动化 api,基本上我想做的是执行 test_001_post_desafio,将其响应中的信息保存在列表中并在 test_002_post_validate 中使用它,但是当使用 pytest 执行后者时出现错误:“SKIPPED [1] test_email .py:43: 得到空参数集 ['otp', 'idOtp', 'subdomain']"

我究竟做错了什么?

subdominios = ["20", "21", "22", "23", "24", "25", "99", "22", "11"]
desafios = []

#This works fine!!!
@pytest.mark.parametrize("subdominio", [subdominio for subdominio in subdominios])
def test_001_post_desafio(subdominio, payload, header):
    response_create = requests.post(
        "some url" + subdominio,
        data=json.dumps(payload),
        headers=header,
        verify=False)
    response_json = response_create.json()
    #Here i append the data i need for test_002_post_validate
    desafios.append((response_json["otp"], response_json["idOtp"], subdominio))
    assert response_create.status_code == 200


#here is where i get SKIPPED [1] test_email.py:43: got empty parameter set ['otp', 'idOtp', 'subdominio']
@pytest.mark.parametrize("otp, idOtp, subdominio", [otp for otp in desafios])
def test_002_post_validate(otp, idOtp, subdominio, header):
    response = requests.post("some Url 1" + idOtp +
                             "some url2" + subdominio,
        data=json.dumps({"otp": otp}),
        headers=header,
        verify=False)
    assert response.status_code == 204

我可以在测试用例中完成整个测试,但我认为它不是很优雅

4

0 回答 0