Tuesday, 15 April 2014

How can I force my Python unit tests to print tracebacks after error logs? -



How can I force my Python unit tests to print tracebacks after error logs? -

i'm attempting unit test complex network stuff, , every time there's error, networking libraries output hundreds of lines of log messages. thing i'm interested in actual traceback of error, have scroll through log messages see traceback.

is there way forcefulness python's unittest module output tracebacks after logs instead of other way around?

for example, see following:

====================================================================== error: my_test (tests.mytest) ---------------------------------------------------------------------- traceback (most recent phone call last): file "my_code_file.py", line 39, in my_function my_module.my_function() file "my_code_file.py", line 78, in my_function raise exception("my exception here") exception: exception here -------------------- >> begin captured logging << -------------------- <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> -------------------- >> end captured logging << --------------------

i see can see errors after running tests:

====================================================================== -------------------- >> begin captured logging << -------------------- <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> <<< hundreds of lines of logs networking libraries/wiretraces/etc>>> -------------------- >> end captured logging << -------------------- error: my_test (tests.mytest) ---------------------------------------------------------------------- traceback (most recent phone call last): file "my_code_file.py", line 39, in my_function my_module.my_function() file "my_code_file.py", line 78, in my_function raise exception("my exception here") exception: exception here

what using logging module?

honestly not sure function utilize best results.

however, there logging.exception

ex:

import logging try: print blah except exception, e: logging.exception("\n\n !!!!!! \n\n {} \n\n !!!!!! \n\n".format(e))

output on exception arising nicely visible:

error:root: !!!!!! name 'blah' not defined !!!!!! traceback (most recent phone call last): file "<ipython-input-39-99d79696f33a>", line 2, in <module> print blah nameerror: name 'blah' not defined

python unit-testing python-2.7

No comments:

Post a Comment