From 585b7cbd2f2d39dc961c18e46bdc48f2f30ee042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 20 Sep 2025 20:38:53 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Refactor=20test=20with=20explicit?= =?UTF-8?q?=20stringified=20annotations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_return_none_future_annotations.py | 27 ------------------- ...est_return_none_stringified_annotations.py | 16 +++++++++++ 2 files changed, 16 insertions(+), 27 deletions(-) delete mode 100644 tests/test_return_none_future_annotations.py create mode 100644 tests/test_return_none_stringified_annotations.py diff --git a/tests/test_return_none_future_annotations.py b/tests/test_return_none_future_annotations.py deleted file mode 100644 index 44dee5591..000000000 --- a/tests/test_return_none_future_annotations.py +++ /dev/null @@ -1,27 +0,0 @@ -from __future__ import annotations - -import http -import logging - -from fastapi import APIRouter, FastAPI -from fastapi.testclient import TestClient - -router = APIRouter() - -app = FastAPI() - - -@router.get("/no-content", status_code=http.HTTPStatus.NO_CONTENT) -def return_no_content() -> None: - logging.info("endpoint called") - - -app.include_router(router) - -client = TestClient(app) - - -def test_no_content(): - response = client.get("/no-content") - assert response.status_code == http.HTTPStatus.NO_CONTENT, response.text - assert not response.content diff --git a/tests/test_return_none_stringified_annotations.py b/tests/test_return_none_stringified_annotations.py new file mode 100644 index 000000000..06f151fe3 --- /dev/null +++ b/tests/test_return_none_stringified_annotations.py @@ -0,0 +1,16 @@ +import http + +from fastapi import FastAPI +from fastapi.testclient import TestClient + + +def test_no_content(): + app = FastAPI() + + @app.get("/no-content", status_code=http.HTTPStatus.NO_CONTENT) + def return_no_content() -> "None": ... # pragma: no cover + + client = TestClient(app) + response = client.get("/no-content") + assert response.status_code == http.HTTPStatus.NO_CONTENT, response.text + assert not response.content