[TIP] Skipping with stdlib unittest.py

Marius Gedminas marius at gedmin.as
Fri Jul 24 13:19:03 PDT 2009


On Fri, Jul 24, 2009 at 12:05:12PM -0400, Jean-Paul Calderone wrote:
> 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?

Old-style Zope's solution, paraphrased:

    import unittest
    import doctest

    class TestRegularFeatures(unittest.TestCase)
        ...

    class TestOptionalFeatures(unittest.TestCase)
        ...

    def test_suite():
        suite = unittest.TestSuite()
        suite.addTest(unittest.makeSuite(TestRegularFeatures))
        if optional_feature_available:
            suite.addTest(unittest.makeSuite(TestOptionalFeatures))
        return suite

    if __name__ == '__main__':
        unittest.main(defaultTest='test_suite')

New-style Zope's solution, paraphrased:

    import unittest
    import doctest

    def test_suite():
        suite = unittest.TestSuite()
        suite.addTest(doctest.DocFileSuite('regular-feature.txt'))
        if optional_feature_available:
            suite.addTest(doctest.DocFileSuite('optional-feature.txt'))
        return suite

    if __name__ == '__main__':
        unittest.main(defaultTest='test_suite')

Marius Gedminas
-- 
"Nuclear war can ruin your whole compile."
                -- Karl Lehenbauer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090724/efd635f3/attachment.pgp 


More information about the testing-in-python mailing list