Home > other >  Flask: injection of the "client" parameter using pytest fixture
Flask: injection of the "client" parameter using pytest fixture

Time:07-01

I just can't figure out how pytest determines the parameter "client" in the Flask test suite located in this file.

class SwaggerTest(object):
    def test_specs_endpoint(self, api, client):
        data = client.get_specs("")
        assert data["swagger"] == "2.0"
        assert data["basePath"] == "/"
        assert data["produces"] == ["application/json"]
        assert data["consumes"] == ["application/json"]
        assert data["paths"] == {}
        assert "info" in data

I've looked in the conftest.py file in the same directory but there is no definition of a fixture for "client".

Thanks for your help.

CodePudding user response:

When I see a fixture being used my immediate reaction like you, is to check the conftest.py file. Since it is not defined there, my next thought is to check the testing requirements which leads me to this line. After finding the documentation for pytest-flask we can see that this fixture, client, is defined as a fixture within that library.

  • Related