-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
anyio integration #1157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anyio integration #1157
Changes from 37 commits
d06f40c
75310b5
a660684
42b83cb
9870a1f
6997eb9
e1c2adb
de84b4a
e91ec33
7e2cd46
03e312e
fd4569e
d785513
58d5331
268547d
57b2f79
444a3ac
4d31a60
681c348
01dd813
9f76d42
5c8818d
f0e4cd8
376f9db
34da2b4
31cc220
73590aa
4192bf7
3a4b472
cc3be48
9b6e722
b8c43cf
d51d5ff
82431f4
2504237
87c614c
cf915bc
72586ba
1800f7a
89e2dae
f62a2ec
edba5dc
60d95e1
fc60420
27283aa
3cce6a9
cbc2e68
c4d49a7
4dd8c5d
dde5079
df53965
6e0f05f
3a359e3
5c77b7d
390b7a1
e420181
6a3f94d
0c225a3
5667a4b
19685db
4e43146
a1ceb35
63cfcb9
efbe6a1
6208ca5
8e6115b
e0c9967
27ec6f7
2b9dd22
643d107
d0ca3f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,21 @@ 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)`. | ||
|
|
||
| ### Selecting the Async backend | ||
|
|
||
| `TestClient.async_backend` is a dictionary which allows you to set the options | ||
| for the backend used to run tests. These options are passed to | ||
| `anyio.start_blocking_portal()`. By default, `asyncio` is used. | ||
|
||
|
|
||
| To run `Trio`, set `async_backend["backend"] = "trio"`, for example: | ||
|
|
||
| ```python | ||
| def test_app() | ||
| client = TestClient(app) | ||
| client.async_backend["backend"] = "trio" | ||
JayH5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ... | ||
| ``` | ||
|
|
||
| ### Testing WebSocket sessions | ||
|
|
||
| You can also test websocket sessions with the test client. | ||
|
|
@@ -72,6 +87,8 @@ always raised by the test client. | |
|
|
||
| May raise `starlette.websockets.WebSocketDisconnect` if the application does not accept the websocket connection. | ||
|
|
||
| `websocket_connect()` must be used as a context manager (in a `with` block). | ||
|
|
||
| #### Sending data | ||
|
|
||
| * `.send_text(data)` - Send the given text to the application. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ isort==5.* | |
| mypy | ||
| pytest | ||
| pytest-cov | ||
| pytest-asyncio | ||
| trio | ||
|
|
||
| # Documentation | ||
| mkdocs | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import typing | ||
|
|
||
| import anyio | ||
|
|
||
| from starlette.datastructures import State, URLPath | ||
| from starlette.exceptions import ExceptionMiddleware | ||
| from starlette.middleware import Middleware | ||
|
|
@@ -109,7 +111,9 @@ def url_path_for(self, name: str, **path_params: str) -> URLPath: | |
|
|
||
| async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: | ||
| scope["app"] = self | ||
| await self.middleware_stack(scope, receive, send) | ||
| task_group = scope["task_group"] = anyio.create_task_group() | ||
|
||
| async with task_group: | ||
| await self.middleware_stack(scope, receive, send) | ||
|
||
|
|
||
| # The following usages are now discouraged in favour of configuration | ||
| # during Starlette.__init__(...) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.