Skip to content

Latest commit

 

History

History
19 lines (10 loc) · 1.29 KB

console-output-from-unittest.md

File metadata and controls

19 lines (10 loc) · 1.29 KB

Produce console output from a unit test

Unit tests generally swallow console output, especially stdout.

That makes it difficult to troubleshoot problems uncovered by failing unit tests. But you can using the logging library to produce formatted output.

Just import logging as log and then do log.warn("{0}", something.different). Warnings are sent do stderr and would normally not be trapped by the unittest framework.

If your test is intercepting stderr, then you may need to be a bit more sophisticated in your use of the logging library.

Credits

That, and more, can be found in this Slashdot answer.


© 2017 Dave Hein

Creative Commons License
This work by Dave Hein is licensed under a Creative Commons Attribution 4.0 International License.