views:

46

answers:

2

I'm using Python's unittest module for unit testing.

I'd like to be able to report informational messages as part of the unit test output—other than pass/fail status. Specifically in my case, I want to report whether the module under test is using the pure Python implementation or the C extension.

Is there a mechanism in unittest to output informational messages as part of the test report? Can it be done in alternative Python unit test frameworks?

+2  A: 

Yes, you can use nosetests, which has a plugin system which allows this. For example the TestResult api allows to provide extended reporting:

Provides a TextTestResult that extends unittest’s _TextTestResult to provide support for error classes (such as the builtin skip and deprecated classes), and hooks for plugins to take over or extend reporting.

Olivier
+1  A: 

I wasn't aware of nosetests and it might make sense to use that plugin for a variety of reasons. I would use the logging module myself.

colgur
Do you know of any existing Python projects you could point us to, which use that method?
Craig McQueen
Sorry Craig, I don't know of a project off-hand. Have you used logging before? It's super flexible in terms of output. Throw up some sample code and we'll work it.
colgur
Now I've tried out logging, and it's super useful. I hadn't thought of using it in unit tests in this way. Thanks for the idea.
Craig McQueen
Cool, glad to hear it.
colgur