Performance: Test fixtures with pytest
MEDIUM IMPACT
This concept affects test execution speed and resource usage during Flask app testing.
import pytest @pytest.fixture def client(): app = create_app() with app.test_client() as client: yield client def test_one(client): response = client.get('/') assert response.status_code == 200 def test_two(client): response = client.get('/about') assert response.status_code == 200
def test_one(): app = create_app() client = app.test_client() response = client.get('/') assert response.status_code == 200 def test_two(): app = create_app() client = app.test_client() response = client.get('/about') assert response.status_code == 200
| Pattern | Setup Calls | Resource Usage | Test Duration | Verdict |
|---|---|---|---|---|
| Repeated app creation in each test | N times for N tests | High CPU and memory | Longer total test time | [X] Bad |
| Shared pytest fixture for client | Once per test function | Lower CPU and memory | Faster test execution | [OK] Good |