Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ kerberos = [

[dependency-groups]
test = [
"pytest~=8.4.2",
"pytest~=9.2.0",
"httpx2~=2.16.0",
"pytest-asyncio>=0.26.0,<1.0",
"pytest-asyncio~=1.5.0",
"pytest-randomly~=5.1.0",
"pytest-rerunfailures~=16.1",
"pytest-deadfixtures~=3.1.0",
"pytest-rerunfailures~=16.2",
"pytest-mock~=3.17.0",
"pytest-lazy-fixtures~=1.4.0",
"pytest-clarity~=1.0.1",
Expand Down Expand Up @@ -230,6 +229,7 @@ markers = [
"postgres: tests on Postgres",
"oracle: tests for Oracle",
"clickhouse: tests for Clickhouse",
"iceberg: tests for Iceberg",
"mysql: tests for MySQL",
"mssql: tests for MSSQL",
"hdfs: tests for hadoop hdfs",
Expand All @@ -240,6 +240,11 @@ markers = [
"samba: tests for Samba",
"webdav: tests for WebDAV",
]
asyncio_default_fixture_loop_scope = "session"
asyncio_default_test_loop_scope = "session"
filterwarnings = [
"ignore:Module already imported so cannot be rewritten:pytest.PytestAssertRewriteWarning",
]

[tool.coverage.run]
source_pkgs = ["syncmaster"]
Expand Down
23 changes: 13 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging
import os
import time
Expand All @@ -13,6 +12,7 @@
from celery import Celery
from fastapi import FastAPI
from httpx2 import ASGITransport, AsyncClient
from sqlalchemy import delete
from sqlalchemy.ext.asyncio import (
AsyncEngine,
AsyncSession,
Expand Down Expand Up @@ -55,14 +55,6 @@ def _generate_access_token(user_id: int) -> str:
return _generate_access_token


@pytest.fixture(scope="session")
def event_loop():
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()


@pytest.fixture(scope="session", params=[{}])
def settings(request: pytest.FixtureRequest) -> Settings:
return Settings.model_validate(request.param)
Expand Down Expand Up @@ -114,12 +106,23 @@ async def sessionmaker(async_engine: AsyncEngine):

@pytest_asyncio.fixture
async def session(sessionmaker: async_sessionmaker[AsyncSession]):
session: AsyncSession = sessionmaker()

try:
session: AsyncSession = sessionmaker()
yield session
await session.commit()
except Exception:
await session.rollback()
raise
finally:
await session.close()

# cleanup everything the test created
async with sessionmaker() as another_session:
for table in reversed(Base.metadata.sorted_tables):
await another_session.execute(delete(table))
await another_session.commit()


@pytest.fixture(scope="session")
def mocked_celery() -> Celery:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,4 @@ async def clickhouse_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
import secrets
from collections.abc import Callable

import pytest
import pytest_asyncio
from sqlalchemy.ext.asyncio import AsyncSession

from syncmaster.db.models import Group
from syncmaster.server.settings import ServerAppSettings as Settings
from tests.mocks import MockUser, UserTestRoles
from tests.test_unit.utils import create_group, create_queue, create_user


@pytest_asyncio.fixture
async def group_owner(
settings: Settings,
session: AsyncSession,
access_token_factory,
access_token_factory: Callable[[int], str],
):
user = await create_user(
session=session,
username=secrets.token_hex(5),
)

token = access_token_factory(user.id)
yield MockUser(
return MockUser(
user=user,
auth_token=token,
role=UserTestRoles.Owner,
)

await session.delete(user)
await session.commit()


@pytest_asyncio.fixture
async def group(
session: AsyncSession,
group_owner: MockUser,
):
result = await create_group(session=session, name=secrets.token_hex(5), owner_id=group_owner.user.id)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture(params=["123-test_queue"])
Expand All @@ -55,6 +49,4 @@ async def queue(
group_id=group.id,
slug=request.param,
)
yield result
await session.delete(result)
await session.commit()
return result
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async def ftp_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result


@pytest.fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async def ftps_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result


@pytest.fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,4 @@ async def hdfs_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,4 @@ async def hive_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,4 @@ async def iceberg_rest_s3_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,4 @@ async def mssql_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,4 @@ async def mysql_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,4 @@ async def oracle_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,4 @@ async def postgres_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,4 @@ async def s3_connection(
),
)

yield syncmaster_conn
await session.delete(syncmaster_conn)
await session.commit()
return syncmaster_conn
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def samba_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result


@pytest.fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ async def sftp_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result


@pytest.fixture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ async def webdav_connection(
),
)

yield result
await session.delete(result)
await session.commit()
return result


@pytest.fixture(
Expand Down
8 changes: 2 additions & 6 deletions tests/test_integration/test_run_transfer/test_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ async def postgres_to_clickhouse(
transformations=transformations,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture
Expand Down Expand Up @@ -91,9 +89,7 @@ async def clickhouse_to_postgres(
transformations=transformations,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest.mark.parametrize(
Expand Down
8 changes: 2 additions & 6 deletions tests/test_integration/test_run_transfer/test_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ async def ftp_to_postgres(
strategy_params=strategy,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture(params=[""])
Expand Down Expand Up @@ -108,9 +106,7 @@ async def postgres_to_ftp(
strategy_params=strategy,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest.mark.parametrize(
Expand Down
8 changes: 2 additions & 6 deletions tests/test_integration/test_run_transfer/test_ftps.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ async def ftps_to_postgres(
strategy_params=strategy,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture(params=[""])
Expand Down Expand Up @@ -107,9 +105,7 @@ async def postgres_to_ftps(
strategy_params=strategy,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest.mark.parametrize(
Expand Down
8 changes: 2 additions & 6 deletions tests/test_integration/test_run_transfer/test_hdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ async def hdfs_to_postgres(
},
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture(params=[""])
Expand Down Expand Up @@ -104,9 +102,7 @@ async def postgres_to_hdfs(
strategy_params=strategy,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest.mark.parametrize(
Expand Down
8 changes: 2 additions & 6 deletions tests/test_integration/test_run_transfer/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def postgres_to_hive(
transformations=transformations,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest_asyncio.fixture
Expand Down Expand Up @@ -81,9 +79,7 @@ async def hive_to_postgres(
transformations=transformations,
queue_id=queue.id,
)
yield result
await session.delete(result)
await session.commit()
return result


@pytest.mark.parametrize(
Expand Down
Loading
Loading