scholarr/tests/unit/services/domains/arxiv/conftest.py
Justin Visser 87aa89b58c fix: resolve mypy errors, fix arxiv test session isolation, and add premerge script
- Remove unused type:ignore comment in scholars.py
- Fix 51 mypy errors across test files (Any return types, cast(), protocol stubs)
- Fix arxiv unit test failures caused by session isolation (patch_session_factory fixture)
- Fix integration test rate-limit bleed between search and create
- Add scripts/premerge.sh for local CI verification
- Add docs/website/.docusaurus/ to .gitignore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 12:46:10 +01:00

17 lines
755 B
Python

from __future__ import annotations
import pytest
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
@pytest.fixture
def patch_session_factory(db_session: AsyncSession, monkeypatch: pytest.MonkeyPatch):
"""Patch get_session_factory in arxiv modules to use the test's DB engine.
Without this, the implementation creates its own engine via get_session_factory()
which may not share transaction visibility with the test's db_session fixture.
"""
factory = async_sessionmaker(db_session.bind, expire_on_commit=False)
monkeypatch.setattr("app.services.arxiv.rate_limit.get_session_factory", lambda: factory)
monkeypatch.setattr("app.services.arxiv.cache.get_session_factory", lambda: factory)
return factory