[TIP] Skipping with stdlib unittest.py

Michał Kwiatkowski constant.beta at gmail.com
Mon Jul 27 12:52:51 PDT 2009


On Sat, Jul 25, 2009 at 12:32 AM, Frank Niessink<frank at niessink.com> wrote:
> In the Task Coach (http://www.taskcoach.org) test suite we sometimes
> need to skip tests on certain platforms. We use two simple decorators
> for that:
>
> def ignore(*args, **kwargs):
>   pass
>
> def runTest(func):
>   return func
>
> def onlyOnPlatform(*platforms):
>   ''' Decorator for unit tests that only run on specific platforms. '''
>   return runTest if wx.Platform in platforms else ignore
>
> def skipOnPlatform(*platforms):
>   ''' Decorator for unit tests that are to be skipped on specific
>       platforms. '''
>   return ignore if wx.Platform in platforms else runTest
>
> These are used like this:
>
>   @test.skipOnPlatform('__WXMSW__') # GetItemBackgroundColour
> doesn't work on Windows
>   def testEffortColor(self): # pragma: no cover
>       self.task.setColor(wx.RED)
>       self.task.addEffort(self.effort1)
>       self.assertEqual(wx.RED, self.viewer.widget.GetItemBackgroundColour(0))

It is an interesting idea, although it has slightly different
semantics than the SkipTest used by other test frameworks. If I
understand your code correctly, decorating a test with @skipOnPlatform
will cause a test to "dissappear" from a test suite, i.e. it will not
be reported at all. Test runners like nose clearly show skipped tests,
so it's easy to keep track of what is skipped and what is actually
run.

In big test suites test cases tend to get lost sometimes, for
different reasons. I wonder what is your experience with this skip
test scheme - does it cause tests to get lost from time to time?

Cheers,
mk



More information about the testing-in-python mailing list