You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It adds startup functions to the broker, so it imports your aiohttp application and creates a single worker-wide Request and Application objects that you can depend on.
27
27
28
28
THIS REQUEST IS NOT RELATED TO THE ACTUAL REQUESTS IN AioHTTP! This request won't have actual data about the request you were handling while sending a task.
29
+
30
+
31
+
## Manual context updates
32
+
33
+
Sometimes it's required to update context manually. For example, for tests.
34
+
If you need to add context in your broker by hand, please use function populate_context.
35
+
36
+
Imagine, you want to use InMemoryBroker for testing and your broker file looks like this:
37
+
38
+
```python
39
+
broker = MyBroker()
40
+
41
+
if env =="pytest":
42
+
broker = InMemoryBroker()
43
+
```
44
+
45
+
In this case your context won't be updated, because inmemory brokers cannot run as workers.
46
+
To solve this issue, we have a populate context function. It's a bit complex and takes lots of
47
+
parmeters. But here's a fixture that creates aiohttp test client and populates context of inmemory broker.
48
+
49
+
```python
50
+
import asyncio
51
+
from typing import AsyncGenerator
52
+
53
+
import pytest
54
+
from aiohttp import web
55
+
from aiohttp.test_utils import BaseTestServer, TestClient, TestServer
0 commit comments