← Flask learning pathFlask · Module 9 of 10
Testing Flask apps
Write tests with pytest and the Flask test client.
📖 Key ideas
- pytest is the common test runner.
- app.test_client() sends fake requests.
- Use fixtures to create the app and a test database.
- Assert status codes and JSON: assert res.status_code == 200.
- Run tests in CI on every push.
💡 Real-life example: The test client is a robot customer that visits every page and reports problems.
pytestPython test framework
test_clientSimulates HTTP requests
FixtureReusable test setup
TESTINGConfig flag for test mode