Skip to content

Commit 221170f

Browse files
committed
Use in memory sqlite db for tests
1 parent cf55417 commit 221170f

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

tests/conftest.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import inspect
2-
import os
32
from contextlib import _AsyncGeneratorContextManager, asynccontextmanager
43
from typing import Tuple, Type, Union
54
from uuid import uuid4
@@ -80,29 +79,18 @@ async def f(cm):
8079

8180
@pytest.fixture
8281
def sa_manager() -> SQLAlchemyBindManager:
83-
test_sync_db_path = f"./{uuid4()}.db"
84-
test_async_db_path = f"./{uuid4()}.db"
8582
config = {
8683
"sync": SQLAlchemyConfig(
87-
engine_url=f"sqlite:///{test_sync_db_path}",
84+
engine_url="sqlite://",
8885
engine_options=dict(connect_args={"check_same_thread": False}),
8986
),
9087
"async": SQLAlchemyAsyncConfig(
91-
engine_url=f"sqlite+aiosqlite:///{test_sync_db_path}",
88+
engine_url="sqlite+aiosqlite://",
9289
engine_options=dict(connect_args={"check_same_thread": False}),
9390
),
9491
}
9592

9693
yield SQLAlchemyBindManager(config)
97-
try:
98-
os.unlink(test_sync_db_path)
99-
except FileNotFoundError:
100-
pass
101-
102-
try:
103-
os.unlink(test_async_db_path)
104-
except FileNotFoundError:
105-
pass
10694

10795
clear_mappers()
10896

tests/repository/test_composite_pk.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
from typing import Type
3-
from uuid import uuid4
42

53
import pytest
64
from sqlalchemy import Column, Integer, String
@@ -15,17 +13,12 @@
1513

1614
@pytest.fixture
1715
def sa_manager() -> SQLAlchemyBindManager:
18-
test_db_path = f"./{uuid4()}.db"
1916
config = SQLAlchemyConfig(
20-
engine_url=f"sqlite:///{test_db_path}",
17+
engine_url="sqlite://",
2118
engine_options=dict(connect_args={"check_same_thread": False}),
2219
session_options=dict(expire_on_commit=False),
2320
)
2421
yield SQLAlchemyBindManager(config)
25-
try:
26-
os.unlink(test_db_path)
27-
except FileNotFoundError:
28-
pass
2922
clear_mappers()
3023

3124

tests/test_sqlalchemy_bind_manager.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from uuid import uuid4
2-
31
import pytest
42
from sqlalchemy import MetaData
53
from sqlalchemy.ext.asyncio import AsyncSession
@@ -21,7 +19,7 @@
2119
{"bind_name": "Invalid Config"},
2220
{
2321
"valid": SQLAlchemyConfig(
24-
engine_url=f"sqlite:///{uuid4}.db",
22+
engine_url="sqlite://",
2523
engine_options=dict(connect_args={"check_same_thread": False}),
2624
session_options=dict(expire_on_commit=False),
2725
),

0 commit comments

Comments
 (0)