refactor(tests): one definition each for the copied fixtures and fakes (#2825, milestone 296 area 1)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 8s
CI & Build / integration (push) Successful in 24s
CI & Build / TypeScript typecheck (push) Successful in 32s
CI & Build / Python tests (push) Successful in 54s
CI & Build / Build & push image (push) Successful in 18s

The shape ledger showed the same test scaffolding defined over and over:
_bind_user x12 (byte-identical), _dispose_engine x10 in three wordings,
_no_supersession x3, _make_mock_session x7 in three subsets, a get-or-create
User helper x2 (+3 inlined), and fifteen hand-rolled MagicMock note factories
each re-explaining the same "an auto-MagicMock attribute is truthy" hazard
(note 2109).

Now: conftest.py carries _bind_user / _dispose_engine / _no_supersession as
opt-in fixtures (pytestmark = usefixtures(...) per module, so unit tests pay
nothing), and tests/helpers.py carries make_mock_session(), ensure_user() and
fake_note(**attrs) — the hazard documented once, real values on every
attribute the product reads. Call sites were rewritten by AST so titles with
dashes and commas survived; the three SimpleNamespace _note stand-ins that
only feed a single function stay local.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-21 11:03:48 -04:00
co-authored by Claude Fable 5
parent dad56a51bd
commit bbee0d0db1
38 changed files with 316 additions and 609 deletions
+3 -22
View File
@@ -24,6 +24,8 @@ a DB-touching path with only mocked coverage is a path with no coverage).
import pytest
import pytest_asyncio
from tests.helpers import ensure_user
from scribe.services.snippets import (
VERIFY_CHANGED,
VERIFY_OK,
@@ -79,34 +81,13 @@ def test_verification_records_and_reads_back_the_checked_commit():
# --- integration: the rules through the real service paths -------------------
@pytest_asyncio.fixture
async def _dispose_engine():
from scribe.models import engine
yield
await engine.dispose()
@pytest_asyncio.fixture
async def user_id(_dispose_engine):
# Get-or-create: the lane's database persists across tests, so a second
# test re-creating the same username dies on the unique constraint.
from sqlalchemy import select
from scribe.models import async_session
from scribe.models.user import User
async with async_session() as s:
existing = (
await s.execute(
select(User).where(User.username == "snippet_prov_itest")
)
).scalar_one_or_none()
if existing is not None:
return existing.id
user = User(username="snippet_prov_itest")
s.add(user)
await s.flush()
uid = user.id
uid = (await ensure_user(s, "snippet_prov_itest")).id
await s.commit()
return uid