Open-source personal finance manager. Self-hosted, privacy-first.
fix: harden test suite against env leakage and pytest-asyncio 1.x
Tássio Noronhae2fd5b6e0e42
diff --git a/backend/pyproject.toml b/backend/pyproject.tomlindex 88a22134..6b075fe4 100644--- a/backend/pyproject.toml+++ b/backend/pyproject.toml@@ -24,7 +24,7 @@ dependencies = [[project.optional-dependencies]dev = ["pytest>=7.4.0",- "pytest-asyncio>=0.23.0",+ "pytest-asyncio>=0.23.0,<1.0","pytest-cov>=4.1.0","httpx>=0.26.0","aiosqlite>=0.19.0",diff --git a/backend/tests/conftest.py b/backend/tests/conftest.pyindex 828f39ec..5ae3c66c 100644--- a/backend/tests/conftest.py+++ b/backend/tests/conftest.py@@ -3,7 +3,9 @@ import uuidfrom datetime import date, datetime, timezonefrom decimal import Decimalfrom typing import AsyncGenerator+from unittest.mock import AsyncMock, patch+import pytestimport pytest_asynciofrom httpx import ASGITransport, AsyncClientfrom sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker@@ -279,3 +281,25 @@ async def test_rules(for rule in rules:await session.refresh(rule)return rules++[email protected](autouse=True)+def _no_external_fx_sync():+ """Prevent tests from hitting the real OpenExchangeRates API."""+ with patch("app.services.fx_rate_service._provider") as mock_provider:+ mock_provider.name = "test"+ mock_provider.fetch_latest = AsyncMock(return_value={})+ mock_provider.fetch_historical = AsyncMock(return_value={})+ yield++[email protected](autouse=True)+def _reset_provider_registry():+ """Reset the provider registry so local env config doesn't leak into tests."""+ from app.providers import _PROVIDERS++ original = dict(_PROVIDERS)+ _PROVIDERS.clear()+ yield+ _PROVIDERS.clear()+ _PROVIDERS.update(original)diff --git a/backend/tests/test_recurring_transaction_service.py b/backend/tests/test_recurring_transaction_service.pyindex 50dd103c..3513d947 100644--- a/backend/tests/test_recurring_transaction_service.py+++ b/backend/tests/test_recurring_transaction_service.py@@ -3,6 +3,7 @@ from datetime import datefrom decimal import Decimalimport pytest+import pytest_asynciofrom sqlalchemy import selectfrom sqlalchemy.ext.asyncio import AsyncSession@@ -21,7 +22,7 @@ from app.services.recurring_transaction_service import ()+@pytest_asyncio.fixtureasync def test_account_for_recurring(session: AsyncSession, test_user) -> Account:account = Account(id=uuid.uuid4(),diff --git a/backend/tests/test_transaction_service.py b/backend/tests/test_transaction_service.pyindex b4ed747b..91cfe01a 100644--- a/backend/tests/test_transaction_service.py+++ b/backend/tests/test_transaction_service.py@@ -3,6 +3,7 @@ from datetime import date, datetime, timezonefrom decimal import Decimalimport pytest+import pytest_asynciofrom sqlalchemy.ext.asyncio import AsyncSessionfrom app.models.account import Account@@ -19,7 +20,7 @@ from app.services.transaction_service import ()+@pytest_asyncio.fixtureasync def txn_account(session: AsyncSession, test_user) -> Account:account = Account(id=uuid.uuid4(),