Skip to content

Instantly share code, notes, and snippets.

@devops-school
Created December 1, 2023 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devops-school/d6ef65f294c90db3aec02179d84bb4e9 to your computer and use it in GitHub Desktop.
Save devops-school/d6ef65f294c90db3aec02179d84bb4e9 to your computer and use it in GitHub Desktop.
Python Test Runners - pytest-trio
# pip install pytest pytest-trio
# my_module.py
import trio
async def trio_async_operation():
async with trio.open_nursery() as nursery:
nursery.start_soon(trio_async_task)
async def trio_async_task():
await trio.sleep(1) # Simulate an asynchronous operation
# tests/test_trio_code.py
# In this code, we use the @pytest.mark.trio decorator to mark the test function as a Trio-based asynchronous test. Inside the test, we use Trio's event loop to start the asynchronous operation.
import pytest
import trio
from my_module import trio_async_operation
@pytest.mark.trio
async def test_trio_async_operation():
async with trio.open_nursery() as nursery:
nursery.start_soon(trio_async_operation)
# pytest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment