Skip to content

Commit 635a78c

Browse files
committed
test: modify tests to mock new clasess
1 parent 9e48962 commit 635a78c

File tree

3 files changed

+281
-164
lines changed

3 files changed

+281
-164
lines changed

tests/conftest.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
# tests/conftest.py
2-
from unittest.mock import MagicMock, patch
2+
from unittest.mock import AsyncMock, MagicMock, patch
33

44
import pytest
55
from fastapi.testclient import TestClient
66

7+
# Mock databases before any imports - patch where they're USED not where they're defined
8+
_mock_engine_patch = patch("app.services.auth_service.get_odmantic_engine")
9+
_mock_driver_patch = patch("app.services.auth_service.get_graph_db_driver")
10+
11+
_mock_engine = _mock_engine_patch.start()
12+
_mock_driver = _mock_driver_patch.start()
13+
14+
_mock_engine.return_value = AsyncMock()
15+
_mock_driver.return_value = MagicMock()
16+
17+
18+
def pytest_sessionfinish(session, exitstatus):
19+
"""Clean up mocks after test session"""
20+
_mock_engine_patch.stop()
21+
_mock_driver_patch.stop()
22+
23+
24+
@pytest.fixture(autouse=True)
25+
def reset_auth_service_singleton():
26+
"""Reset AuthService instances before each test"""
27+
yield
28+
729

830
@pytest.fixture(scope="module")
931
def client():
10-
with patch("app.services.dbs.databases.get_odmantic_engine") as mock_get_engine:
11-
mock_get_engine.return_value = MagicMock()
12-
from app.main import app # Importa después de aplicar el patch
13-
with TestClient(app) as c:
14-
yield c
32+
from app.main import app
33+
with TestClient(app) as c:
34+
yield c

0 commit comments

Comments
 (0)