1212
1313import pytest
1414import pytest_asyncio
15+ from _pytest .fixtures import FixtureRequest
1516
1617from mcp_code_indexer .database .database import DatabaseManager
1718from mcp_code_indexer .database .models import FileDescription , Project
@@ -41,6 +42,26 @@ async def temp_db() -> AsyncGenerator[Path, None]:
4142 db_path .unlink ()
4243
4344
45+ @pytest_asyncio .fixture
46+ async def temp_db_with_test_table (temp_db : Path ) -> AsyncGenerator [Path , None ]:
47+ """Create a temporary database with a test table for retry testing."""
48+ import aiosqlite
49+
50+ # Create database with tables
51+ async with aiosqlite .connect (temp_db ) as db :
52+ await db .execute (
53+ """
54+ CREATE TABLE test_table (
55+ id INTEGER PRIMARY KEY,
56+ data TEXT NOT NULL
57+ )
58+ """
59+ )
60+ await db .commit ()
61+
62+ yield temp_db
63+
64+
4465@pytest_asyncio .fixture
4566async def db_manager (temp_db : Path ) -> AsyncGenerator [DatabaseManager , None ]:
4667 """Create and initialize a database manager for testing."""
@@ -53,6 +74,24 @@ async def db_manager(temp_db: Path) -> AsyncGenerator[DatabaseManager, None]:
5374 await manager .close_pool ()
5475
5576
77+ @pytest_asyncio .fixture
78+ async def temp_db_manager_pool (
79+ temp_db : Path , request : FixtureRequest
80+ ) -> AsyncGenerator [DatabaseManager , None ]:
81+ """Create and initialize a database manager with specified pool size for testing.
82+
83+ Use with @pytest.mark.parametrize("temp_db_manager_pool", [pool_size], indirect=True)
84+ """
85+ pool_size = request .param
86+ manager = DatabaseManager (temp_db , pool_size = pool_size )
87+ await manager .initialize ()
88+
89+ yield manager
90+
91+ # Cleanup
92+ await manager .close_pool ()
93+
94+
5695@pytest_asyncio .fixture
5796async def sample_project (db_manager : DatabaseManager ) -> Project :
5897 """Create a sample project for testing."""
@@ -293,10 +332,8 @@ async def mcp_server(tmp_path: Path):
293332
294333 # Import here to avoid circular imports
295334 from mcp_code_indexer .server .mcp_server import MCPCodeIndexServer
296-
297- server = MCPCodeIndexServer (
298- token_limit = 1000 , db_path = db_path , cache_dir = cache_dir
299- )
335+
336+ server = MCPCodeIndexServer (token_limit = 1000 , db_path = db_path , cache_dir = cache_dir )
300337 await server .initialize ()
301338
302339 yield server
0 commit comments