Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test optimizations #168

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
Loading