Skip to content

no-raw-connection-in-tests

Do not execute raw SQL or acquire raw database connections in tests.

Why

Tests that reach through a pool couple assertions and setup to persistence internals, bypass the application boundary, and duplicate transaction ownership.

Fix

Exercise the owning store/service API. Do not move SQL into a test-only probe to hide it. Use an exact SARJ429 suppression for deliberate database bootstrap, migration or transaction fault testing.

Examples

Before — flagged An injected test probe still bypasses the owning store
tests/fixtures/probe.py
from psycopg_pool import AsyncConnectionPool
class Probe:
def __init__(self, pool: AsyncConnectionPool):
self._pool = pool
async def seed(self):
async with self._pool.connection() as conn:
await conn.execute("INSERT INTO jobs (id) VALUES (%s)", (job_id,))
After — preferred A test reads through the owning store API
tests/test_orders.py
async def load_rows(store: OrderStore):
return await store.list_orders()

Formerly: no-raw-sql-in-tests