Skip to content

Commit c0a6d52

Browse files
committed
feat: test optimizations
1 parent a557d39 commit c0a6d52

File tree

7 files changed

+843
-311
lines changed

7 files changed

+843
-311
lines changed

.env.testing

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# App
22
SECRET_KEY='secret-key'
3-
3+
LITESTAR_DEBUG=False
44
# Cache
55
REDIS_URL=redis://localhost:6397/0
66

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repos:
1111
- id: mixed-line-ending
1212
- id: trailing-whitespace
1313
- repo: https://github.com/charliermarsh/ruff-pre-commit
14-
rev: v0.4.8
14+
rev: v0.4.9
1515
hooks:
1616
- id: ruff
1717
args:

package-lock.json

Lines changed: 790 additions & 262 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdm.lock

Lines changed: 35 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ branch = true
140140
omit = ["tests/*", "**/*/migrations/**/*.py", "scripts/*"]
141141

142142
[tool.pytest.ini_options]
143-
addopts = ["-ra", "--ignore", "migrations"]
143+
addopts = ["-ra", "--ignore", "migrations", "-n", "2", "--dist", "loadfile"]
144144
# env_files = [".env.testing"]
145145
# env_override_existing_values = 1
146146
filterwarnings = [

tests/data_fixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def fx_app(pytestconfig: pytest.Config, monkeypatch: MonkeyPatch) -> Litestar:
2525
return create_app()
2626

2727

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

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

7575

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

tests/integration/conftest.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
pytestmark = pytest.mark.anyio
2626

2727

28-
@pytest.fixture(name="engine", autouse=True)
28+
@pytest.fixture(name="engine", autouse=True, scope="session")
2929
async def fx_engine(
3030
postgres_docker_ip: str,
3131
postgres_service: None,
@@ -55,18 +55,12 @@ async def fx_engine(
5555
)
5656

5757

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

6262

63-
@pytest.fixture(name="session")
64-
async def fx_session(sessionmaker: async_sessionmaker[AsyncSession]) -> AsyncGenerator[AsyncSession, None]:
65-
async with sessionmaker() as session:
66-
yield session
67-
68-
69-
@pytest.fixture(autouse=True)
63+
@pytest.fixture(autouse=True, scope="session")
7064
async def _seed_db(
7165
engine: AsyncEngine,
7266
sessionmaker: async_sessionmaker[AsyncSession],
@@ -104,6 +98,16 @@ async def _seed_db(
10498
yield
10599

106100

101+
@pytest.fixture(name="session", scope="session")
102+
async def fx_session(sessionmaker: async_sessionmaker[AsyncSession]) -> AsyncGenerator[AsyncSession, None]:
103+
async with sessionmaker() as session:
104+
try:
105+
session.begin_nested()
106+
yield session
107+
finally:
108+
await session.rollback()
109+
110+
107111
@pytest.fixture(autouse=True)
108112
def _patch_db(
109113
app: "Litestar",

0 commit comments

Comments
 (0)