Performance: Fixture organization
MEDIUM IMPACT
This affects test suite startup time and memory usage, impacting how quickly tests can run and how responsive the development feedback loop is.
import pytest @pytest.fixture(scope='session') def db_connection(): conn = create_connection() yield conn conn.close() def test_one(db_connection): assert db_connection.is_connected() def test_two(db_connection): assert db_connection.is_connected()
import pytest @pytest.fixture def db_connection(): conn = create_connection() yield conn conn.close() def test_one(db_connection): assert db_connection.is_connected() def test_two(db_connection): assert db_connection.is_connected()
| Pattern | Setup Calls | Teardown Calls | Resource Usage | Verdict |
|---|---|---|---|---|
| Function-scoped fixture | Runs before each test | Runs after each test | High (repeated connections) | [X] Bad |
| Session-scoped fixture | Runs once per test session | Runs once after all tests | Low (shared connection) | [OK] Good |