-
-
Notifications
You must be signed in to change notification settings - Fork 601
Add failing test to ensure OpenAPI does not execute lifespan #1167
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import pytest | ||
| from fastapi import FastAPI | ||
| from main import generate_openapi_json | ||
|
|
||
|
|
||
| def test_openapi_failure_does_not_crash_app(monkeypatch): | ||
| def broken_openapi(*args, **kwargs): | ||
| raise Exception("Simulated failure") | ||
|
|
||
| monkeypatch.setattr( | ||
| "main.get_openapi", | ||
| broken_openapi | ||
| ) | ||
|
|
||
| app = FastAPI() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused
🤖 Prompt for AI Agents |
||
|
|
||
| try: | ||
| generate_openapi_json() | ||
| started = True | ||
| except Exception: | ||
| started = False | ||
|
|
||
| assert started, "App should not crash if OpenAPI generation fails" | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Remove unused import.
FastAPI(line 2) is imported but the instance created from it is unused by the test logic.pytest(line 1) is fine sincemonkeypatchis a pytest fixture.Proposed fix
import pytest -from fastapi import FastAPI from main import generate_openapi_json📝 Committable suggestion
🤖 Prompt for AI Agents