Skip to content
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
Empty file added backend/app/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions backend/tests/test_openapi_lifespan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from fastapi import FastAPI
Comment on lines +1 to +2
Copy link
Contributor

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 since monkeypatch is a pytest fixture.

Proposed fix
 import pytest
-from fastapi import FastAPI
 from main import generate_openapi_json
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import pytest
from fastapi import FastAPI
import pytest
from main import generate_openapi_json
🤖 Prompt for AI Agents
In `@backend/tests/test_openapi_lifespan.py` around lines 1 - 2, Remove the unused
FastAPI import: the test file imports FastAPI but never uses it, so delete the
FastAPI import token to avoid unused-import warnings; keep the pytest import for
fixtures like monkeypatch and ensure only pytest remains in the import
statement.

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()
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Unused FastAPI instance — not connected to generate_openapi_json().

generate_openapi_json() operates on the module-level app object defined in main.py, not on this local instance. This line (and the FastAPI import on line 2) has no effect and is misleading, as it suggests the test exercises this app.

🤖 Prompt for AI Agents
In `@backend/tests/test_openapi_lifespan.py` at line 15, Remove the unused local
FastAPI() instance and its import from the test; instead reference the
module-level app used by generate_openapi_json() (i.e., rely on
generate_openapi_json() from the application module or import the module-level
app if needed) so the test actually exercises generate_openapi_json() rather
than a stray local app variable; delete the line creating app = FastAPI() and
the FastAPI import and update imports to call generate_openapi_json() from the
application module.


try:
generate_openapi_json()
started = True
except Exception:
started = False

assert started, "App should not crash if OpenAPI generation fails"