-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
60 lines (42 loc) · 1.69 KB
/
conftest.py
File metadata and controls
60 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Pytest configuration and fixtures for aria tests."""
import pytest
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
def _reset_all_db_singletons():
"""Reset all database singletons so the next call creates fresh ones."""
from aria.tools.database import ToolsDatabase
from aria.tools.knowledge.database import KnowledgeDatabase
from aria.tools.planner.database import PlannerDatabase
from aria.tools.reasoning.database import ReasoningDatabase
from aria.tools.scratchpad.database import ScratchpadDatabase
ToolsDatabase._instance = None
ReasoningDatabase._instance = None
PlannerDatabase._instance = None
ScratchpadDatabase._instance = None
KnowledgeDatabase._instance = None
import aria.tools.database as db_module
db_module._db_instance = None
# Reset lazy module-level caches
import aria.tools.planner.registry as planner_reg
import aria.tools.reasoning.registry as reasoning_reg
reasoning_reg._db = None
planner_reg._db = None
@pytest.fixture()
def test_tools_db(tmp_path):
"""Create a temporary ToolsDatabase for test isolation.
This fixture resets all database singletons, creates a fresh
ToolsDatabase pointing at a temp file, and cleans up afterwards.
The temp file is automatically deleted by pytest's ``tmp_path``.
Usage in test modules::
def test_something(test_tools_db):
...
"""
from aria.tools.database import ToolsDatabase
_reset_all_db_singletons()
db_path = str(tmp_path / "test_tools.db")
test_db = ToolsDatabase(db_path)
test_db.create_tables()
yield test_db
test_db.close()
_reset_all_db_singletons()