Skip to content

Commit

Permalink
Explain 'TestClient(app) as client' vs 'client = TestClient(app)' (#1… (
Browse files Browse the repository at this point in the history
encode#1747)

* Explain 'TestClient(app) as client' vs 'client = TestClient(app)' (encode#1733)

* Nit (encode#1733)

* Update docs/testclient.md (encode#1733)

Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>

* Update docs/testclient.md

Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>

* Update docs/testclient.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update docs/testclient.md

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
3 people committed Jul 10, 2022
1 parent e7717af commit 643c3f2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/testclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ application. Occasionally you might want to test the content of 500 error
responses, rather than allowing client to raise the server exception. In this
case you should use `client = TestClient(app, raise_server_exceptions=False)`.

!!! note

If you want the `TestClient` to run `lifespan` events (`on_startup`, `on_shutdown`, or `lifespan`),
you will need to use the `TestClient` as a context manager. Otherwise, the events
will not be triggered when the `TestClient` is instantiated. You can learn more about it
[here](/events/#running-event-handlers-in-tests).

### Selecting the Async backend

`TestClient` takes arguments `backend` (a string) and `backend_options` (a dictionary).
Expand Down

0 comments on commit 643c3f2

Please sign in to comment.