1

I am trying to automate an api, basically what I want to do is execute test_001_post_desafio, save information from its response in a list and use it in test_002_post_validate, but when executing the latter with pytest I get the error: "SKIPPED [1] test_email.py:43: got empty parameter set ['otp', 'idOtp', 'subdomain']"

What am I doing wrong?

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

I could do the whole test inside a testcase, but I think it is not very elegant

nismotri
  • 87
  • 2
  • 12
Fedex
  • 11
  • 2
  • 2
    The parameters get evaluated at load time, not at run time, so the list is still empty at that point. It is generally not a good idea to make tests dependent on each other this way. If you cannot split the precondition out (which would be the better solution), it is better to use the same test as you did before. – MrBean Bremen Apr 29 '21 at 14:55

0 Answers0