I've just released logot
- a log capture and assertion plugin 🚀
#11966
Unanswered
etianen
asked this question 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, which as the title says, is a log capture and assertion plugin.
logot
has a few unique things, such as being logging-framework-agnostic and having support for testing highly concurrent code using threads or async. But those things are relatively niche. What I'd like to show here are a few examples of how it can be a nicecaplog
replacement, even in "normal" synchronous code.As a
caplog
replacementHere's a really simple example testing that a piece of code logs as expected:
You'll see a couple of things here. A
logot
fixture, and alogged
API. Use these together to make neat little log assertions. The equivalent code usingcaplog
would be:I think the
logot
code is clearer, and hopefully you do too! 🤗Log message matching
One of
logot
s more useful features is the ability to match log messages using%
-style placeholders rather than regex. This syntax was chosen to be as close as possible to the%
placeholders used by the stdliblogging
library.The equivalent using
caplog
gets pretty verbose:If your message contained everyday punctuation like
.
, you have to start worrying about regex escaping too! I hope that%
-style message matching gives a clearer, more loggy way of matching log messages.Log pattern matching
This feature is generally aimed towards testing code using threads or async, where messages can arrive out-of-order. But it's also useful for testing synchronous code.
This example tests whether the
INFO
log "Something happened" or theERROR
"Something broke!" was emitted, and passes on either. The equivalent usingcaplog
gets quite long: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