Skip to content

Restructure fixtures#309

Merged
PGijsbers merged 5 commits intomainfrom
restructure-fixtures
Apr 10, 2026
Merged

Restructure fixtures#309
PGijsbers merged 5 commits intomainfrom
restructure-fixtures

Conversation

@PGijsbers
Copy link
Copy Markdown
Contributor

Restructure fixtures to reduce per-test fixture overhead.

Quite significant speedups for the `php_api` suite, locally from
140s to 90s.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

Warning

Rate limit exceeded

@PGijsbers has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 6 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1fc2d19f-f116-42b2-88e9-d3c6b78e0109

📥 Commits

Reviewing files that changed from the base of the PR and between a009075 and ca84f29.

📒 Files selected for processing (2)
  • src/main.py
  • tests/conftest.py

Walkthrough

Updated async type annotations and test fixtures. In src/main.py the lifespan(app: FastAPI | None) return annotation changed from AsyncGenerator[None, None] to AsyncIterator[None] (signature now documents the app parameter). In src/routers/dependencies.py expdb_connection and userdb_connection now return AsyncIterator[AsyncConnection]; fetch_user’s annotation was simplified to AsyncGenerator[User | None]. tests/conftest.py removes an autouse one_lifespan fixture, adds a session-scoped app fixture using LifespanManager, updates py_api to use the shared app, and makes php_api session-scoped. A test fixture’s inner context manager annotation changed to AsyncIterator[None].

Possibly related PRs

  • openml/server-api PR 308: Modifies the same lifespan signature and converts AsyncGenerator return types to AsyncIterator in overlapping files.
  • openml/server-api PR 243: Alters async lifecycle and dependency generator declarations with related AsyncGenerator→AsyncIterator conversions.
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Restructure fixtures' directly and concisely summarizes the main change: reorganizing test fixtures to improve efficiency.
Description check ✅ Passed The description 'Restructure fixtures to reduce per-test fixture overhead' explains the purpose of the changes and relates directly to the fixture modifications throughout the codebase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch restructure-fixtures

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The session-scoped app fixture has its dependency_overrides mutated in the function-scoped py_api fixture but never reset, so consider clearing or restoring app.dependency_overrides after each test to avoid cross-test leakage of overrides.
  • The comment in py_api about not using the Lifespan manager and relying on the removed one_lifespan fixture is now outdated and should be updated or removed to reflect the new fixture structure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The session-scoped `app` fixture has its `dependency_overrides` mutated in the function-scoped `py_api` fixture but never reset, so consider clearing or restoring `app.dependency_overrides` after each test to avoid cross-test leakage of overrides.
- The comment in `py_api` about not using the Lifespan manager and relying on the removed `one_lifespan` fixture is now outdated and should be updated or removed to reflect the new fixture structure.

## Individual Comments

### Comment 1
<location path="tests/conftest.py" line_range="105-106" />
<code_context>
     app.dependency_overrides[expdb_connection] = override_expdb
     app.dependency_overrides[userdb_connection] = override_userdb
+
     # We do not use the Lifespan manager for now because our auto-use fixture
     # `one_lifespan` will do setup and teardown at a session scope level instead.
     async with httpx.AsyncClient(
</code_context>
<issue_to_address>
**suggestion:** Update or remove the outdated comment about not using the Lifespan manager.

After the fixture restructuring, the session-scoped `app` fixture now uses `LifespanManager` and the `one_lifespan` fixture no longer exists, so this comment no longer reflects reality. Please adjust it to describe the current fixture setup (session-scoped `app` with `LifespanManager` plus function-scoped DB fixtures) or remove it to avoid confusion.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.57%. Comparing base (058fea0) to head (ca84f29).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #309   +/-   ##
=======================================
  Coverage   93.56%   93.57%           
=======================================
  Files          72       72           
  Lines        3109     3113    +4     
  Branches      222      222           
=======================================
+ Hits         2909     2913    +4     
  Misses        143      143           
  Partials       57       57           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/main.py (1)

40-43: ⚠️ Potential issue | 🔴 Critical

Await shutdown tasks in the lifespan cleanup.

At line 40, asyncio.gather() is called but never awaited, preventing logger.complete() and close_databases() from executing. This causes resource leaks on shutdown.

Proposed fix
-    asyncio.gather(
+    await asyncio.gather(
         logger.complete(),
         close_databases(),
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main.py` around lines 40 - 43, The shutdown code calls
asyncio.gather(...) but does not await it, so logger.complete() and
close_databases() never run; update the lifespan cleanup to await the gather
call (await asyncio.gather(...)) or await each coroutine directly so
logger.complete() and close_databases() are executed and resources are closed;
locate the gather invocation using asyncio.gather and the coroutines
logger.complete() and close_databases() and change the call to be awaited.
tests/conftest.py (1)

102-113: ⚠️ Potential issue | 🟠 Major

Restore dependency overrides after each py_api use to prevent test contamination.

The overrides set at lines 102–103 are applied to a session-scoped app instance and never restored, leaving stale overrides that can affect subsequent tests. Additionally, the comment at lines 105–106 references a one_lifespan fixture that no longer exists in the codebase.

Proposed fix
-    app.dependency_overrides[expdb_connection] = override_expdb
-    app.dependency_overrides[userdb_connection] = override_userdb
-
-    # We do not use the Lifespan manager for now because our auto-use fixture
-    # `one_lifespan` will do setup and teardown at a session scope level instead.
-    async with httpx.AsyncClient(
-        transport=httpx.ASGITransport(app=app),
-        base_url="http://test",
-        follow_redirects=True,
-    ) as client:
-        yield client
+    previous_expdb_override = app.dependency_overrides.get(expdb_connection)
+    previous_userdb_override = app.dependency_overrides.get(userdb_connection)
+    app.dependency_overrides[expdb_connection] = override_expdb
+    app.dependency_overrides[userdb_connection] = override_userdb
+    try:
+        async with httpx.AsyncClient(
+            transport=httpx.ASGITransport(app=app),
+            base_url="http://test",
+            follow_redirects=True,
+        ) as client:
+            yield client
+    finally:
+        if previous_expdb_override is None:
+            app.dependency_overrides.pop(expdb_connection, None)
+        else:
+            app.dependency_overrides[expdb_connection] = previous_expdb_override
+
+        if previous_userdb_override is None:
+            app.dependency_overrides.pop(userdb_connection, None)
+        else:
+            app.dependency_overrides[userdb_connection] = previous_userdb_override
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/conftest.py` around lines 102 - 113, The session-scoped dependency
overrides (app.dependency_overrides) set for expdb_connection and
userdb_connection must be restored after the py_api fixture to avoid test
contamination: wrap the override assignment and the async httpx.AsyncClient
context in a try/finally, capture any previous overrides for expdb_connection
and userdb_connection before assigning override_expdb/override_userdb, yield the
client inside the try, and in the finally restore the originals (or delete the
keys if originals were None); also remove or update the stale comment
referencing the non-existent one_lifespan fixture.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/main.py`:
- Around line 40-43: The shutdown code calls asyncio.gather(...) but does not
await it, so logger.complete() and close_databases() never run; update the
lifespan cleanup to await the gather call (await asyncio.gather(...)) or await
each coroutine directly so logger.complete() and close_databases() are executed
and resources are closed; locate the gather invocation using asyncio.gather and
the coroutines logger.complete() and close_databases() and change the call to be
awaited.

In `@tests/conftest.py`:
- Around line 102-113: The session-scoped dependency overrides
(app.dependency_overrides) set for expdb_connection and userdb_connection must
be restored after the py_api fixture to avoid test contamination: wrap the
override assignment and the async httpx.AsyncClient context in a try/finally,
capture any previous overrides for expdb_connection and userdb_connection before
assigning override_expdb/override_userdb, yield the client inside the try, and
in the finally restore the originals (or delete the keys if originals were
None); also remove or update the stale comment referencing the non-existent
one_lifespan fixture.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c9c75871-d0ea-4335-adf4-a01e88ca723d

📥 Commits

Reviewing files that changed from the base of the PR and between 058fea0 and f75bb99.

📒 Files selected for processing (4)
  • src/main.py
  • src/routers/dependencies.py
  • tests/conftest.py
  • tests/routers/openml/migration/setups_migration_test.py

@PGijsbers PGijsbers merged commit e90ec4d into main Apr 10, 2026
9 checks passed
@PGijsbers PGijsbers deleted the restructure-fixtures branch April 10, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant