[TIP] Skipping with stdlib unittest.py
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
>def ignore(*args, **kwargs):
> return func
> ''' Decorator for unit tests that only run on specific platforms. '''
> return runTest if wx.Platform in platforms else ignore
> ''' 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.assertEqual(wx.RED, self.viewer.widget.GetItemBackgroundColour(0))
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.
More information about the testing-in-python