Skip to content

Commit f3ff0fe

Browse files
committed
create common for tests (get sqla_uri from env)
1 parent 6e520ce commit f3ff0fe

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

tests/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from os import getenv
2+
from pathlib import Path
3+
4+
5+
def sqla_uri():
6+
testing_db_url = getenv("TESTING_DB_URL")
7+
if not testing_db_url:
8+
db_dir = Path(__file__).resolve().parent
9+
testing_db_url = f"sqlite+aiosqlite:///{db_dir}/db.sqlite3"
10+
return testing_db_url

tests/fixtures/db_connection.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
from pathlib import Path
2-
31
from pytest import fixture # noqa PT013
42
from pytest_asyncio import fixture as async_fixture
53
from sqlalchemy.engine import make_url
64
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
75
from sqlalchemy.orm import sessionmaker
86

7+
from tests.common import sqla_uri
98
from tests.models import Base
109

1110

12-
def sqla_uri():
13-
db_dir = Path(__file__).resolve().parent.parent
14-
return f"sqlite+aiosqlite:///{db_dir}/db.sqlite3"
15-
16-
1711
def get_async_sessionmaker() -> sessionmaker:
1812
engine = create_async_engine(url=make_url(sqla_uri()))
1913
_async_session = sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)

0 commit comments

Comments
 (0)