Skip to content

Commit

Permalink
make test engine autocommit to properly create indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
notarious2 committed Mar 3, 2024
1 parent aa82ae6 commit 6cda453
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 0 additions & 2 deletions tests/chat/router/test_get_user_chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ async def test_get_user_chats_succeeds_given_chat_exists(authenticated_bob_clien
"created_at",
"updated_at",
"users",
"has_new_messages",
"new_messages_count",
}

Expand All @@ -42,6 +41,5 @@ async def test_get_user_chats_succeeds_given_user_has_multiple_chats(
"created_at",
"updated_at",
"users",
"has_new_messages",
"new_messages_count",
}
8 changes: 5 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
f"{settings.DB_USER}:{settings.DB_PASSWORD}@{settings.DB_HOST}:{settings.DB_PORT}/{settings.DB_NAME}"
)
engine_test = create_async_engine(DATABASE_URL_TEST, connect_args={"server_settings": {"jit": "off"}})
async_session_maker = sessionmaker(engine_test, class_=AsyncSession, expire_on_commit=False)
autocommit_engine = engine_test.execution_options(isolation_level="AUTOCOMMIT")

async_session_maker = sessionmaker(autocommit_engine, class_=AsyncSession, expire_on_commit=False)
metadata.bind = engine_test


Expand All @@ -36,14 +38,14 @@ async def override_get_async_session() -> AsyncGenerator[AsyncSession, None]:

@pytest.fixture(scope="session")
async def db_session():
async with engine_test.begin() as conn:
async with autocommit_engine.begin() as conn:
await conn.execute(text(f"CREATE SCHEMA IF NOT EXISTS {settings.DB_SCHEMA}"))
await conn.run_sync(metadata.create_all)
async with async_session_maker() as session:
yield session
await session.flush()
await session.rollback()
async with engine_test.begin() as conn:
async with autocommit_engine.begin() as conn:
await conn.execute(text(f"DROP SCHEMA {settings.DB_SCHEMA} CASCADE"))


Expand Down

0 comments on commit 6cda453

Please sign in to comment.