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’s 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