diff --git a/tests/test_snippet_provenance.py b/tests/test_snippet_provenance.py index ef35941..ac60ac5 100644 --- a/tests/test_snippet_provenance.py +++ b/tests/test_snippet_provenance.py @@ -88,10 +88,21 @@ async def _dispose_engine(): @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()