Skip to main content

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")

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.

Release files for logassert 1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logassert 1
File Size Uploaded
logassert-1.tar.gz 5.5 kB Details

Release files / logassert-1.tar.gz

Download URL logassert-1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c8ee6a6acc80ffdf82a7101caec3658994dc331f5f9c0c1a2f47e52f921a8f9c
BLAKE2b-256 checksum
How to use checksums
84903930b4bb530b24b2834c7d5d08baa4529a17e7d5359aaddabbe8ec889986
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

8.6

2 release files

8.5

2 release files

8.4

2 release files

8.3

2 release files

8.2

2 release files

8.1

2 release files

8

2 release files

7

2 release files

6

2 release files

5

2 release files

4

1 release file

3

1 release file

2

1 release file

This release

1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page