I've just released logot
- a log capture and assertion plugin 馃殌
#782
etianen
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! 馃憢 I've just released logot, a log capture and assertion plugin for
pytest
.I've posted a show and tell in the
pytest
forum about using it as a replacement forcaplog
. But that's actually one of the less-interesting parts of the plugin, to me at least! What I'd like to show here is an example of using it to test highly concurrent asynchronous code. 馃檱Testing concurrent async code 馃Ф
Imagine the following code running in an
asyncio.Task
:Testing this sort of code is tricky, as it's running in a loop and not returning a value. You probably want to check that
app.data
has been fetched correctly, but with this code running in a background task, you have no way of knowing when that is.While it鈥檚 possible to rewrite this code in a way that can be tested without
logot
, that risks making the code less clear or more verbose. For complex asynchronous code, this can quickly become burdensome. 馃憥But testing this code with
logot
is easy!You'll see a couple of things here. A
logot
fixture, and alogged
API. Use these together to make neat little log assertions. Thelogot.await_for(...)
method pauses your async test task until the expected logs arrive, or a configurabletimeout
expires.Bells and whistles 馃敂
The
logot.await_for(...)
API is pretty powerful and includes:%
-style placeholders.I hope you like it! 鉂わ笍
This is only a v1 release, but it's building on a lot of ideas I've been developing in different projects for a while now. I hope you like it, and find it useful.
The project documentation and pytest integeration guide are there if you'd like to find out more. 馃檱
Beta Was this translation helpful? Give feedback.
All reactions