unittest: new reporting category "skipped"
Jeremy Fincher
tweedgeezer at hotmail.com
Thu Sep 23 11:40:46 EDT 2004
Remy Blank <remy.blank_asps at pobox.com> wrote in message news:<mailman.3772.1095935910.5135.python-list at python.org>...
> 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.
In my project, I have many tests that require a network connection,
and many others which don't.
> 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".
I agree.
> 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(...)
> ...
With all the argument that's happened on this list regarding
decorators and conditional expressions and whatnot, I had been
wondering whether anyone here came up with good ideas anymore. But
you've certainly given a counterexample for that notion: your idea is
golden.
> If the echo is positive, I will make an initial implementation and
> provide a patch for feedback.
Even if it doesn't get accepted into Python proper, I'll take a copy
and put it with my project -- I already provide my own unittest.py
that I hacked to show the total number of asserts (I was curious one
day, and it's turned out to be a remarkably useful thing to have,
since my tests-upon-tests can hide unreaonable numbers of assertions
which otherwise would go unnoticed (except as a general slowness of
the test suite).
Jeremy
More information about the Python-list
mailing list