File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99# Test Database URL
1010TEST_DATABASE_URL = "sqlite+aiosqlite:///test_commitguard.db"
1111
12+
1213@pytest .fixture (autouse = True , scope = "session" )
1314def override_db_url ():
1415 """Override database URL for the entire test session."""
@@ -17,6 +18,7 @@ def override_db_url():
1718 yield
1819 settings .DATABASE_URL = original_url
1920
21+
2022@pytest .fixture (autouse = True )
2123async def setup_test_db ():
2224 """Initialize test database before each test."""
@@ -35,8 +37,10 @@ async def setup_test_db():
3537
3638 # Patch src.agents.learning if it's already imported
3739 import sys
40+
3841 if "src.agents.learning" in sys .modules :
3942 import src .agents .learning
43+
4044 src .agents .learning .AsyncSessionLocal = new_session_local
4145
4246 async with database .engine .begin () as conn :
@@ -50,9 +54,10 @@ async def setup_test_db():
5054 await database .engine .dispose ()
5155 database .engine = original_engine
5256 database .AsyncSessionLocal = original_session_local
53-
57+
5458 if "src.agents.learning" in sys .modules :
5559 import src .agents .learning
60+
5661 src .agents .learning .AsyncSessionLocal = original_session_local
5762
5863 if os .path .exists ("test_commitguard.db" ):
You can’t perform that action at this time.
0 commit comments