Python unittest2.SkipTest and general suggestion

Ganesh Pal ganesh1pal at
Sun Feb 21 13:03:06 EST 2016

On Sun, Feb 21, 2016 at 10:33 PM, Ben Finney <ben+python at> wrote:

> You are already supplying a custom message to ‘self.skipTest’::
>     except Exception as exc:
>         logging.error(exc)
>         raise unittest.SkipTest("Failure running Integrity Scan ")
> So you can change that message by including the text representation of
> the exception object::
>     except Exception as exc:
>         logging.error(exc)
>         raise unittest.SkipTest(
>                 "Failure running Integrity Scan: {exc}".format(exc=exc))

Thank you for the pointers , but I modified my code to use raise
instead of exception , just wondering how will I display the message
with the below code ,

Sample code :

import os
    import unittest2 as unittest
except ImportError:
    import unittest

class MyTests(unittest.TestCase):
    def setUpClass(cls):
        #x = False
        x = None
        if not x:
            raise unittest.SkipTest(
                "class setup failed")

    def test_one(self):
        print "test_one"

    def test_two(self):
        print "test_two"

if __name__ == "__main__":


gpal-3c6dc81-1# python
Ran 0 tests in 0.000s

OK (skipped=1)

More information about the Python-list mailing list