Skip to main content

Extend Python's "unittest" to better handle "logging" messages

Project description

Utterless

Extend Python's "unittest" to better handle "logging" messages

There's a problem when you try to run a unittest test suite in a codebase which also uses the logging framework: You see your nice output of dots (...F....SS....F..) clogged up with lots of log messages.

For occasional cases you can supress log messages in a block of code with self.assertLogs(...). But that doesn't scale when almost every test in your suite generates messages.

Alternatively you can fiddle your log levels so that all log messages get supressed. But when you have a failing test the log messages can be very helpful in debugging it.

Wouldn't it be great to have an alternative log runner that captures all log messages. If the test fails the messages get displayed with the error traceback. But if the test succeeds then the log messages get silently discarded.

Look no further! This is possibly the package you want.

Usage

We assume you already have a test suite that you run something like this:

$ python -m unittest discover

Having installed utterless you just need to replace that with:

$ python -m utterless discover

Optional Usage

Utterless has mechanisms to integrate with some frameworks that don't run tests through unittest directly.

For example, with Django you can specify the Utterless test runner on the command line:

$ ./manage.py test --testrunner utterless.contrib.django.DiscoverRunner

or by editing settings.py to contain:

TEST_RUNNER = "utterless.contrib.django.DiscoverRunner"

Licence

This software copyright P. S. Clarke and is licensed in accordance with the BSD Three-Clause Licence.

Limitations and Roadmap

  • Currently it completely ignores the warnings module, so output from that (e.g. a DeprecationWarning or a ResourceWarning) will still splurts across the screen. I could possibly collect that up during tests and include it at the end. The complication is that warnings should probably still be emited regardless of whether the test passed or failed. Treating warnings as errors might be the better option.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utterless-0.4.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

utterless-0.4.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file utterless-0.4.1.tar.gz.

File metadata

  • Download URL: utterless-0.4.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for utterless-0.4.1.tar.gz
Algorithm Hash digest
SHA256 e209c575c2f3a6c5a775fa782ddadc3ae8858db0e9e48509730e5e6b9a612c94
MD5 cf148095ac6ea135c8841f079bf0b92e
BLAKE2b-256 b66094e5d1bd326912718bec40abb38daa6edd66a59a698da050939ac02063ef

See more details on using hashes here.

File details

Details for the file utterless-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: utterless-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for utterless-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8c1cd4b8db2104d7dfe9201a578da4008c004498dc8d1607f64a6e1f3673e782
MD5 64e57565f12baad0c89b9c5b02891b22
BLAKE2b-256 ba066b28ecb70337eaf5a6048f615ee1651ec623587e6396403c2bbb2efbd4f8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page