Log Assertion
What?
A simple log assertion mechanism for Python unittests.
Why?
As is vox populi, you must also test the logging calls in your programs.
With logassert this is now very easy.
Awesome! How to use it?
All you need to do is to call this module’s setup() passing the test case instance, and the logger you want to supervise.
Like:
class MyTestCase(unittest.TestCase):
"""Example."""
def setUp(self):
logassert.setup(self, 'mylogger')
In the example, mylogger is the name of the logging to supervise. If different subsystems of your code log in other loggers, this tester won’t notice.
Then, to use it, just call the assertLogged method and it’s family, passing all the strings you want to find.
Example:
def test_blah(self):
(...)
self.assertLoggedDebug('secret', 'life', '42')
That line will check that “secret”, “life” and “42” are all logged in the same logging call, in DEBUG level.
So, if you logged this, the test will pass:
logger.debug("The secret of life, the universe and everything is %d", 42)
Note that the message checked is the one with all parameters replaced.
But if you logged any of the following, the test will fail (the first because it misses one of the string, the second because it has the wrong log level):
logger.debug("The secret of life, the universe and everything is lost")
logger.info("The secret of life, the universe and everything is 42")
What can I test?
You’ll have at disposition several assertion methods:
self.assertLogged: will check that the strings were logged, no matter at which level
self.assertLoggedLEVEL (being LEVEL one of Error, Warning, Info, or Debug): will check that the strings were logged at that specific level.
self.assertNotLogged: will check that the strings were NOT logged, no matter at which level
self.assertNotLoggedLEVEL (being LEVEL one of Error, Warning, Info, or Debug): will check that the strings were NOT logged at that specific level.
Nice! But…
If you need help, or have any question, or found any issue, please open a ticket here.
Thanks in advance for your time.
Metadata
Release files for logassert 2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logassert-2.tar.gz | 5.8 kB | Without provenance | Details for logassert-2.tar.gz |
Release files / logassert-2.tar.gz
| Download URL | logassert-2.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a36d029ca69f905caeb00f2da56a4fd5d82b4a6c0d653e2dfa7674102218f232
|
|
BLAKE2b-256 checksum How to use checksums |
2e90741932ef3e42a7adf71748dee36b191b3ade3d154c41e66bca8393ea97c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for logassert 2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.