Browse Source

Refactor test with explicit stringified annotations

pull/9425/head
Sebastián Ramírez 10 months ago
parent
commit
585b7cbd2f
  1. 27
      tests/test_return_none_future_annotations.py
  2. 16
      tests/test_return_none_stringified_annotations.py

27
tests/test_return_none_future_annotations.py

@ -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

16
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
Loading…
Cancel
Save