Using with trio
¶
Use Logot.await_for()
to pause your test until the expected logs arrive or the timeout
expires:
from logot import Logot, logged
async def test_app(logot: Logot) -> None:
async with trio.open_nursery() as nursery:
nursery.start_soon(app.start())
await logot.await_for(logged.info("App started"))
Note
Use the timeout
argument to Logot.await_for()
to configure how long to wait before the test fails. This can
be configured globally with the timeout
argument to Logot
, defaulting to Logot.DEFAULT_TIMEOUT
.
See also
See Log pattern matching for examples of how to wait for logs that may arrive in an unpredictable order.
Installing¶
Ensure logot
is installed alongside a compatible trio
version by adding the trio
extra:
pip install 'logot[trio]'
See also
See Installing package extras usage guide.
Enabling for pytest
¶
Enable trio
support in your pytest configuration:
# pytest.ini or .pytest.ini
[pytest]
logot_async_waiter = logot.trio.TrioWaiter
# pyproject.toml
[tool.pytest.ini_options]
logot_async_waiter = "logot.trio.TrioWaiter"
See also
See Using with pytest usage guide.
Enabling for unittest
¶
Enable trio
support in your logot.unittest.LogotTestCase
:
from logot.trio import TrioWaiter
class MyAppTest(LogotTestCase):
logot_async_waiter = TrioWaiter
See also
See Using with unittest usage guide.
Enabling manually¶
Enable trio
support for your Logot
instance:
from logot.trio import TrioWaiter
logot = Logot(async_waiter=TrioWaiter)
Enable trio
support for a single Logot.await_for()
call:
await logot.await_for(logged.info("App started"), async_waiter=TrioWaiter)
See also
See Logot
and Logot.await_for()
API reference.