Skip to content

Commit 922769f

Browse files
committed
test(conftest): improves the performance (speed) of unit tests
1 parent af4a74b commit 922769f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tests/conftest.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def verify(self, hash: str, password: Union[str, bytes]) -> bool:
7272
raise VerifyMismatchError("Mock mismatch")
7373

7474

75-
@pytest_asyncio.fixture(scope="function")
75+
@pytest_asyncio.fixture(scope="session")
7676
async def async_engine() -> AsyncIterator[AsyncEngine]:
7777
"""Create an in-memory SQLite async engine."""
7878
async_engine = create_async_engine("sqlite+aiosqlite:///:memory:", future=True)
@@ -89,14 +89,19 @@ async def async_engine() -> AsyncIterator[AsyncEngine]:
8989

9090

9191
@pytest_asyncio.fixture(scope="function")
92-
async def async_session(async_engine: AsyncEngine) -> AsyncIterator[AsyncSession]:
92+
async def async_session_maker(async_engine: AsyncEngine) -> AsyncIterator[async_sessionmaker[AsyncSession]]:
9393
"""Provide an AsyncSession bound to the in-memory engine."""
9494
async_session_maker = async_sessionmaker(
9595
async_engine,
9696
class_=AsyncSession,
9797
expire_on_commit=False,
9898
)
99+
yield async_session_maker
100+
99101

102+
@pytest_asyncio.fixture(scope="function")
103+
async def async_session(async_session_maker: async_sessionmaker[AsyncSession]) -> AsyncIterator[AsyncSession]:
104+
"""Provide an AsyncSession bound to the in-memory engine."""
100105
async with async_session_maker() as session:
101106
yield session
102107

0 commit comments

Comments
 (0)