[TIP] Skipping with stdlib unittest.py

Jean-Paul Calderone exarkun at divmod.com
Mon Jul 27 08:08:46 PDT 2009


On Sat, 25 Jul 2009 00:32:18 +0200, Frank Niessink <frank at niessink.com> wrote:
>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))
>

Hi Frank,

Thanks for the idea.  Of all the suggestions, this one seems to involve the
least effort to implement, so I think I'll probably adopt something like it.

Thanks again,

Jean-Paul



More information about the testing-in-python mailing list