Skip to content

Commit

Permalink
fastapi: improve test client setup
Browse files Browse the repository at this point in the history
You can now pass all kind of args to the TestClient class.
Eg: pass cookies.
  • Loading branch information
simahawk authored and lmignon committed Oct 3, 2024
1 parent e561a79 commit 4206320
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fastapi/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

0 comments on commit 4206320

Please sign in to comment.