Coverage for tests / test_wrapped_method_forward_reference.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import functools 1defg
3from fastapi import FastAPI 1defg
4from fastapi.testclient import TestClient 1defg
6from .forward_reference_type import forwardref_method 1defg
9def passthrough(f): 1defg
10 @functools.wraps(f) 1abc
11 def method(*args, **kwargs): 1abc
12 return f(*args, **kwargs) 1abc
14 return method 1abc
17def test_wrapped_method_type_inference(): 1defg
18 """
19 Regression test ensuring that when a method imported from another module
20 is decorated with something that sets the __wrapped__ attribute (functools.wraps),
21 then the types are still processed correctly, including dereferencing of forward
22 references.
23 """
24 app = FastAPI() 1abc
25 client = TestClient(app) 1abc
26 app.post("/endpoint")(passthrough(forwardref_method)) 1abc
27 app.post("/endpoint2")(passthrough(passthrough(forwardref_method))) 1abc
28 with client: 1abc
29 response = client.post("/endpoint", json={"input": {"x": 0}}) 1abc
30 response2 = client.post("/endpoint2", json={"input": {"x": 0}}) 1abc
31 assert response.json() == response2.json() == {"x": 1} 1abc