unittest: new reporting category "skipped"
George Yoshida
ml at dynkin.com
Thu Sep 23 10:10:56 EDT 2004
Remy Blank wrote:
> Hello unittest users,
> A third solution, and the one I would like to have feedback about,
> is to add the notion of a "skipped" test to unittest. Currently,
> test results are given in terms of tests having either succeeded,
> failed, or generated an error. What about adding a fourth result
> type, skipped, that is also reported at the end of the suite?
>
> 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)
>
> Comments? Ideas?
>
> If the echo is positive, I will make an initial implementation and
> provide a patch for feedback.
Check out TestSkipped.
It's already implemented as a part of utility functions for
unittest module and heavily used in Lib/test directory.
Here's a simple example:
from test.test_support import TestSkipped
class AnythingTest(unittest.TestCase):
def testSomethingAsRoot(self):
if os.geteuid() != 0:
raise TestSkipped, "Must be root"
self.assertEqual(...)
...
def testSomethingAsNormalUser(self):
if os.geteuid() == 0:
raise TestSkipped, "Must be normal user"
self.skipIf(os.geteuid() == 0, "Must be normal user")
self.assertEqual(...)
...
George
More information about the Python-list
mailing list