unittest: new reporting category "skipped"

Remy Blank remy.blank_asps at pobox.com
Thu Sep 23 06:38:26 EDT 2004


Hello unittest users,

In a project I am working on, I have a series of tests that have
to be run as root, and others as a normal user.

One solution is to separate the tests into two different files,
and run the right one. I don't like this too much, as I prefer
to group tests by "function".

Another solution is to build the test suite differently, depending
on the user running it. However, this requires marking the individual
tests with a "category", and have a custom test loader instantiate
only the right ones. I don't have a good solution for this marking.

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.

-- Remy


Remove underscore and suffix in reply address for a timely response.




More information about the Python-list mailing list