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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! 👋 I've just released logot, which as the title says, is a log capture and assertion plugin.
logothas 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 nicecaplogreplacement, even in "normal" synchronous code.As a
caplogreplacementHere's a really simple example testing that a piece of code logs as expected:
You'll see a couple of things here. A
logotfixture, and aloggedAPI. Use these together to make neat little log assertions. The equivalent code usingcaplogwould be:I think the
logotcode is clearer, and hopefully you do too! 🤗Log message matching
One of
logots 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 stdliblogginglibrary.The equivalent using
caploggets 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
INFOlog "Something happened" or theERROR"Something broke!" was emitted, and passes on either. The equivalent usingcaploggets 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