mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 12:49:06 +00:00
refactor: remove excessive comments from test code
- Simplified docstrings to be more concise - Removed obvious line comments that explain basic operations - Kept only essential comments for complex logic - Maintained comments that explain algorithms or non-obvious behavior Based on research, the teardown errors are a known issue with pytest-asyncio and SQLAlchemy async sessions. The recommended approach is to use session-scoped event loops with NullPool, which we already have. The teardown errors don't affect test results and are cosmetic issues related to event loop cleanup.
This commit is contained in:
@@ -9,8 +9,7 @@ from sqlalchemy.pool import NullPool
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def event_loop():
|
||||
"""Creates session-scoped event loop to prevent 'event loop is closed' errors"""
|
||||
# Windows fix for Python 3.8+
|
||||
"""Session-scoped event loop."""
|
||||
if sys.platform.startswith("win") and sys.version_info[:2] >= (3, 8):
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
@@ -124,22 +123,18 @@ async def setup_database(postgres_service):
|
||||
|
||||
settings.DATABASE_URL = DATABASE_URL
|
||||
|
||||
# Create engine with NullPool to prevent connection pooling issues
|
||||
engine = create_async_engine(
|
||||
DATABASE_URL,
|
||||
echo=False,
|
||||
poolclass=NullPool, # Critical: Prevents connection pool issues with asyncpg
|
||||
poolclass=NullPool,
|
||||
)
|
||||
|
||||
async with engine.begin() as conn:
|
||||
# Drop all tables first to ensure clean state
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
# Create all tables
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
yield
|
||||
|
||||
# Cleanup - properly dispose of the engine
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
@@ -154,11 +149,10 @@ async def session(setup_database):
|
||||
|
||||
from reflector.settings import settings
|
||||
|
||||
# Create a new engine with NullPool for this session
|
||||
engine = create_async_engine(
|
||||
settings.DATABASE_URL,
|
||||
echo=False,
|
||||
poolclass=NullPool, # Use NullPool to avoid connection caching issues
|
||||
poolclass=NullPool,
|
||||
)
|
||||
|
||||
async_session_maker = async_sessionmaker(
|
||||
|
||||
Reference in New Issue
Block a user