From 420632057bfe9a6293ed3ec5a3f491df6eae5335 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Mon, 8 Apr 2024 15:54:57 +0200 Subject: [PATCH] fastapi: improve test client setup You can now pass all kind of args to the TestClient class. Eg: pass cookies. --- fastapi/tests/common.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fastapi/tests/common.py b/fastapi/tests/common.py index 2ed646dcf..7e21ce8a6 100644 --- a/fastapi/tests/common.py +++ b/fastapi/tests/common.py @@ -69,6 +69,7 @@ def _create_test_client( env: Environment = None, dependency_overrides: dict[Callable[..., Any], Callable[..., Any]] = None, raise_server_exceptions: bool = True, + testclient_kwargs=None, ): """ Create a test client for the given app or router. @@ -112,7 +113,12 @@ def _create_test_client( app.include_router(router) app.dependency_overrides = dependencies ctx_token = odoo_env_ctx.set(env) + testclient_kwargs = testclient_kwargs or {} try: - yield TestClient(app, raise_server_exceptions=raise_server_exceptions) + yield TestClient( + app, + raise_server_exceptions=raise_server_exceptions, + **testclient_kwargs, + ) finally: odoo_env_ctx.reset(ctx_token)