Skip to content

Commit

Permalink
feat: test optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
cofin committed Jun 19, 2024
1 parent a557d39 commit c0a6d52
Show file tree
Hide file tree
Showing 7 changed files with 843 additions and 311 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# App
SECRET_KEY='secret-key'

LITESTAR_DEBUG=False
# Cache
REDIS_URL=redis://localhost:6397/0

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.4.8
rev: v0.4.9
hooks:
- id: ruff
args:
Expand Down
1,052 changes: 790 additions & 262 deletions package-lock.json

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ branch = true
omit = ["tests/*", "**/*/migrations/**/*.py", "scripts/*"]

[tool.pytest.ini_options]
addopts = ["-ra", "--ignore", "migrations"]
addopts = ["-ra", "--ignore", "migrations", "-n", "2", "--dist", "loadfile"]
# env_files = [".env.testing"]
# env_override_existing_values = 1
filterwarnings = [
Expand Down
4 changes: 2 additions & 2 deletions tests/data_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def fx_app(pytestconfig: pytest.Config, monkeypatch: MonkeyPatch) -> Litestar:
return create_app()


@pytest.fixture(name="raw_users")
@pytest.fixture(name="raw_users", scope="session")
def fx_raw_users() -> list[User | dict[str, Any]]:
"""Unstructured user representations."""

Expand Down Expand Up @@ -73,7 +73,7 @@ def fx_raw_users() -> list[User | dict[str, Any]]:
]


@pytest.fixture(name="raw_teams")
@pytest.fixture(name="raw_teams", scope="session")
def fx_raw_teams() -> list[Team | dict[str, Any]]:
"""Unstructured team representations."""

Expand Down
22 changes: 13 additions & 9 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
pytestmark = pytest.mark.anyio


@pytest.fixture(name="engine", autouse=True)
@pytest.fixture(name="engine", autouse=True, scope="session")
async def fx_engine(
postgres_docker_ip: str,
postgres_service: None,
Expand Down Expand Up @@ -55,18 +55,12 @@ async def fx_engine(
)


@pytest.fixture(name="sessionmaker")
@pytest.fixture(name="sessionmaker", scope="session")
def fx_session_maker_factory(engine: AsyncEngine) -> async_sessionmaker[AsyncSession]:
return async_sessionmaker(bind=engine, expire_on_commit=False)


@pytest.fixture(name="session")
async def fx_session(sessionmaker: async_sessionmaker[AsyncSession]) -> AsyncGenerator[AsyncSession, None]:
async with sessionmaker() as session:
yield session


@pytest.fixture(autouse=True)
@pytest.fixture(autouse=True, scope="session")
async def _seed_db(
engine: AsyncEngine,
sessionmaker: async_sessionmaker[AsyncSession],
Expand Down Expand Up @@ -104,6 +98,16 @@ async def _seed_db(
yield


@pytest.fixture(name="session", scope="session")
async def fx_session(sessionmaker: async_sessionmaker[AsyncSession]) -> AsyncGenerator[AsyncSession, None]:
async with sessionmaker() as session:
try:
session.begin_nested()
yield session
finally:
await session.rollback()


@pytest.fixture(autouse=True)
def _patch_db(
app: "Litestar",
Expand Down

0 comments on commit c0a6d52

Please sign in to comment.