Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbenav committed Jul 29, 2024
1 parent c514187 commit 039076a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions tests/sqlmodel/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,15 @@ class TaskRead(TaskReadSub):
assignee: Optional[UserReadSub]
client: Optional[ClientRead]


def is_docker_running() -> bool: # pragma: no cover
try:
DockerClient()
return True
except Exception:
return False


async_engine = create_async_engine(
"sqlite+aiosqlite:///:memory:", echo=True, future=True
)
Expand All @@ -299,22 +301,26 @@ async def _setup_database(url: str) -> AsyncGenerator[AsyncSession]:


@pytest_asyncio.fixture(scope="function")
async def async_session(request: pytest.FixtureRequest) -> AsyncGenerator[AsyncSession]: # pragma: no cover
async def async_session(
request: pytest.FixtureRequest,
) -> AsyncGenerator[AsyncSession]: # pragma: no cover
dialect_marker = request.node.get_closest_marker("dialect")
dialect = dialect_marker.args[0] if dialect_marker else "sqlite"

if dialect == "postgresql" or dialect == "mysql":
if not is_docker_running():
pytest.skip("Docker is required, but not running")

if dialect == "postgresql":
with PostgresContainer() as postgres:
url = postgres.get_connection_url()
async with _setup_database(url) as session:
yield session
elif dialect == "mysql":
with MySqlContainer() as mysql:
url = make_url(mysql.get_connection_url())._replace(drivername="mysql+aiomysql")
url = make_url(mysql.get_connection_url())._replace(
drivername="mysql+aiomysql"
)
async with _setup_database(url) as session:
yield session
else:
Expand Down

0 comments on commit 039076a

Please sign in to comment.