Nosetests: Capturing log messages written to stderr

This is a tip for using the Python logging module in conjunction with unit-tests.
When using the root logger to write debug messages, e.g.

 import logging
..
logging.debug('x = %s' % x)

to capture the messages and write them to the console when running nosetests, pass ‘root’ to the –log-debug nosetests option. E.g.

nosetests test_module1.py -s --log-debug=root
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s