avast / pytest-docker

Docker-based integration tests
MIT License
427 stars 71 forks source link

How to add parametrize to our test case with pytest-docker? #68

Closed mapattacker closed 2 years ago

mapattacker commented 3 years ago

Hi, I am wondering if it is possible to use @pytest.mark.parametrize together?

In the given example, the http_service fixture is already used, so I'm not sure how to add the parametrize variables in, so that I can send multiple requests to the the dockerized API.

def test_status_code(http_service):
    status = 418
    response = requests.get(http_service + "/status/{}".format(status))

    assert response.status_code == status
Luminaar commented 2 years ago

Hello, sorry it took me so long to respond.

In the unlikely case you are still looking for the solution and for posterity ― it is absolutely possible to use parametrization with the fixture. Here is the example from README with added parametrization:

@pytest.mark.parametrize("status", [418, 401, 503])
def test_status_code(http_service, status):
    response = requests.get(http_service + "/status/{}".format(status))

    assert response.status_code == status