Skip to content

Commit 6330f13

Browse files
author
reinhud
committed
minor fixes in database setup for testing
1 parent 003dc53 commit 6330f13

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/fastapi_server/tests/conftest.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,7 @@ async def apply_migrations(seed_db) -> Generator:
8585

8686
async with async_engine.connect() as async_conn:
8787

88-
async_session = sessionmaker(
89-
async_engine,
90-
expire_on_commit=False,
91-
class_=AsyncSession,
92-
)
93-
94-
# seed the database
95-
async with async_session() as session:
96-
async with session.begin():
97-
session.add_all(seed_db)
98-
88+
# create a test db
9989
await async_conn.run_sync(create_database(TEST_DATABASE))
10090
# use sqlalchemy ddl for initial table setup
10191
await async_conn.run_sync(Base.metadata.create_all)
@@ -109,6 +99,15 @@ async def apply_migrations(seed_db) -> Generator:
10999
)
110100
# apply migrations
111101
await alembic.command.upgrade(config, "head")
102+
# seed the database
103+
async_session = sessionmaker(
104+
async_engine,
105+
expire_on_commit=False,
106+
class_=AsyncSession,
107+
)
108+
async with async_session() as session:
109+
async with session.begin():
110+
session.add_all(seed_db)
112111

113112
yield
114113

0 commit comments

Comments
 (0)