unittest: new reporting category "skipped"

Bernhard Herzog bh at intevation.de
Thu Sep 23 16:33:21 CEST 2004


Remy Blank <remy.blank_asps at pobox.com> writes:

> I imagine something like this:
>
> class AnythingTest(unittest.TestCase):
> 	def testSomethingAsRoot(self):
> 		self.skipIf(os.geteuid() != 0, "Must be root")
>
> 		self.assertEqual(...)
> 		...
>
> 	def testSomethingAsNormalUser(self):
> 		self.skipIf(os.geteuid() == 0, "Must be normal user")
>
> 		self.assertEqual(...)
> 		...
>
> skipIf() would throw a skippedTestException that would be caught
> in TestCase.__call__(). TestResult would be extended with an
> addSkipped() function. The reporting in text mode could be as follows:
>
> FAILED (failures=1, skipped=7)
>
> or
>
> OK (skipped=7)

Amazing, this is practically what I implemented in Thuban (see sig for
URL).  It wasn't very difficult to do that by deriving some custom
classes from the ones in unittest.  Basically, skipped tests raise a
SkipTest exception which is recorded by the test result class not as an
error but as a skipped test.  The relevant code is in test/support.py in
which can be accessed with viewcvs as
http://www.intevation.de/cgi-bin/viewcvs-thuban.cgi/thuban/test/support.py?rev=1.19&content-type=text/vnd.viewcvs-markup


> If the echo is positive, I will make an initial implementation and
> provide a patch for feedback.

I think this would be useful to have.

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                http://sketch.sourceforge.net/
Thuban                                  http://thuban.intevation.org/



More information about the Python-list mailing list