To change default size of page params, you can use CustomizedPage and UseParamsFields customizer:
fromtypingimportTypeVarfromfastapiimportFastAPI,Queryfromfastapi_paginationimportPage,add_pagination,paginatefromfastapi_pagination.customizationimportCustomizedPage,UseParamsFieldsapp=FastAPI()add_pagination(app)T=TypeVar("T")CustomPage=CustomizedPage[Page[T],UseParamsFields(# change default size to be 5, increase upper limit to 1 000size=Query(5,ge=1,le=1_000),),]# req: GET /nums@app.get("/nums")asyncdefget_nums()->CustomPage[int]:returnpaginate(range(1_000))
I'm getting RuntimeError error in my tests, what should I do?¶
If you are getting RuntimeError: Use params, add_pagination or pagination_ctx and had no clue about what should I do.,
the easiest way to fix it is to add call set_params function in your test:
fromfastapi_paginationimportset_params,Paramsdeftest_my_endpoint():set_params(Params(size=10,page=2))# your test code
But better solution will be to make sure that lifespan was called on app that you are testing: