fix: restore dcgm_fakers after lifespan tests#999
Conversation
The lifespan tests drive `async with lifespan(fastapi_app)` directly, which unconditionally appends two `DCGMFaker` entries to the module-level `aiperf_mock_server.app.dcgm_fakers` list. Those appends leak across files: `tests/unit/server/test_app.py::test_dcgm_metrics_invalid_instance` asks for `/dcgm3/metrics` expecting 404, but with 4 fakers in the list it gets 200. Add an autouse fixture that snapshots `dcgm_fakers` on entry and restores it in `finally`, isolating the leak regardless of whether the lifespan body errors out before yield. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Elias Bermudez <dbermudez@nvidia.com>
Try out this PRQuick install: pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@191aef99ba5531ae38d92df6a42a3ebf6e89deadRecommended with virtual environment (using uv): uv venv --python 3.12 && source .venv/bin/activate
uv pip install --upgrade --force-reinstall git+https://github.com/ai-dynamo/aiperf.git@191aef99ba5531ae38d92df6a42a3ebf6e89deadLast updated for commit: |
WalkthroughThe PR adds a pytest fixture that manages test isolation for lifespan tests by capturing the module-level ChangesLifespan test state isolation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/unit/aiperf_mock_server/test_app_lifespan.py`:
- Around line 15-16: The fixture function _restore_dcgm_fakers is missing a
return type annotation; update its signature to annotate the return type as
Generator[None, None, None] (and add "from typing import Generator" if not
already imported) since this pytest fixture yields control, ensuring all
function return types follow the project's type-hinting guideline.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e37e9142-ed8e-4189-ba40-3a1293fb55ba
📒 Files selected for processing (1)
tests/unit/aiperf_mock_server/test_app_lifespan.py
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The lifespan tests drive
async with lifespan(fastapi_app)directly, which unconditionally appends twoDCGMFakerentries to the module-levelaiperf_mock_server.app.dcgm_fakerslist. Those appends leak across files:tests/unit/server/test_app.py::test_dcgm_metrics_invalid_instanceasks for/dcgm3/metricsexpecting 404, but with 4 fakers in the list it gets 200.Add an autouse fixture that snapshots
dcgm_fakerson entry and restores it infinally, isolating the leak regardless of whether the lifespan body errors out before yield.Summary by CodeRabbit