Coverage for tests/test_callable_endpoint.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1from functools import partial 1abcdef

2from typing import Optional 1abcdef

3 

4from fastapi import FastAPI 1abcdef

5from fastapi.testclient import TestClient 1abcdef

6 

7 

8def main(some_arg, q: Optional[str] = None): 1abcdef

9 return {"some_arg": some_arg, "q": q} 1ghijkl

10 

11 

12endpoint = partial(main, "foo") 1abcdef

13 

14app = FastAPI() 1abcdef

15 

16app.get("/")(endpoint) 1abcdef

17 

18 

19client = TestClient(app) 1abcdef

20 

21 

22def test_partial(): 1abcdef

23 response = client.get("/?q=bar") 1ghijkl

24 data = response.json() 1ghijkl

25 assert data == {"some_arg": "foo", "q": "bar"} 1ghijkl