Testing Flask Applications
Learn how to test any Flask application.
Flask test client fixture
In pytest, we can define fixtures to set up and tear down resources needed for the tests. In the case of Flask applications, we can create a fixture for the Flask test client, which allows us to make requests to the application endpoints during testing. Here’s an example of how to define a Flask test client fixture using pytest:
import pytestfrom app import create_app@pytest.fixturedef client():app = create_app()app.config['TESTING'] = Truewith app.test_client() as client:yield client
Flask test client
In the above example, we create a fixture named client
using the pytest.fixture
decorator. Inside the fixture function, we create an instance of the Flask application using the create_app()
function from ...
Access this course and 1400+ top-rated courses and projects.