[TIP] Skipping with stdlib unittest.py

Frank Niessink frank at niessink.com
Fri Jul 24 15:32:18 PDT 2009


2009/7/24 Jean-Paul Calderone <exarkun at divmod.com>:
> Hi all,
>
> I'm curious about what other people do when they're using the stdlib unittest
> module and need to skip tests.  Fortunately, in Python 2.7, skipping features
> will be added, but what have people been doing up until now?

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))

Cheers, Frank



More information about the testing-in-python mailing list