Pytest fixtures for async generators
Project description
Pytest Async Generators
Pytest fixtures for async generators
Usage
Invoke any async generator and call wait_for_messages()
to retrieve the results.
async def count() -> AsyncGenerator[int, None]:
for n in range(10):
await asyncio.sleep(0.1)
yield n
@pytest.mark.asyncio
async def test_counting(subscribe_to_messages) -> None:
subscription = await subscribe_to_messages(count())
messages = await subscription.wait_for_messages()
assert messages == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Note that with real generators you might need to cause events to happen by adding more code after subscribe_to_messages
and before calling wait_for_messages
.
Caveats
The fixture assumes that each message takes approximately the same amount of time because the arrival time of the first message is used to determine the approximate timeout to wait before returning the collected messages. If your generators don't work this way this plugin will make yowon't work correctly and will make you sad.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest_async_generators-0.0.2.tar.gz
.
File metadata
- Download URL: pytest_async_generators-0.0.2.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.10.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad786b6e17d72cbea16d5d31fa7a3e51da19796b85c8f22795624e8f9fe96bd |
|
MD5 | 80947d3a333517691cad3888e1b805e8 |
|
BLAKE2b-256 | 32faef7db8e4b1c5ed6995a24930fab1cc3dde3a0cda615ea45abba5cf2ab531 |
File details
Details for the file pytest_async_generators-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pytest_async_generators-0.0.2-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.4 Linux/5.10.0-23-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f97e06481e05eee0fe34e1926536ca675b51960210a67def34f06fc8d9f84ff |
|
MD5 | 3a9d1c14842338d4c65f79549c7b6fa3 |
|
BLAKE2b-256 | 027e3134677c84762758de524def2e6e048abc11a18433826265f1aca5ab8321 |