Re: Can a test case tell if VERBOSE is used in pyunit test?
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Can a test case tell if VERBOSE is used in pyunit test?

From: Peter Hansen <peter@engcorp.com>
Date: Tue Jan 31 2006 - 04:47:53 CET

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
Received on Tue Feb 7 20:18:45 2006