Can a test case tell if VERBOSE is used in pyunit test?
Peter Hansen
peter at engcorp.com
Mon Jan 30 22:47:53 EST 2006
Noah wrote:
> Is there a way for a test case method in a class derived
> from unittest.TestCase to tell if the harness was started
> with the verbose option? I would like my test cases to
> print out a little extra information if the tests were run with
> -v or -vv.
Looking at the source, it doesn't appear that information is exposed to
the TestCases. If you base your tests on this subclass of the standard
TestCase, however, you can use the regenerated "self._verbosity"
attribute to do what you want:
class TestCase(unittest.TestCase):
def run(self, result=None):
if result.showAll:
self._verbosity = 2
elif result.dots:
self._verbosity = 1
else:
self._verbosity = 0
unittest.TestCase.run(self, result=result)
-Peter
More information about the Python-list
mailing list