Skipping test using unittest SkipTest and exit status

Ganesh Pal ganesh1pal at gmail.com
Fri May 13 12:23:47 EDT 2016


Hi Team,

Iam on  python 2.7 and Linux . I need inputs on the below  program  ,

Iam skipping the unittest  from setUpClass in following way  # raise
unittest.SkipTest(message)

The test are getting skipped but   I have two problem .

(1) This script  is in turn read by other  scripts  which considers the
test have passed based on the scripts return code , but the test have
actually been skipped   ,  How do include an exit status to indicates that
the test have failed

(2) Why is the message  in the raise statement  i.e  raise
 unittest.SkipTest("Class setup failed skipping test") not  getting
displayed .

Also thinking if we could replace raise  unittest.SkipTest with assert
statement ?


Sample code:

#!/usr/bin/env python
import unittest
import logging

class ScanTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        """
        Initial setup before unittest run
        """
        pdb.set_trace()
        self.scan = False
        if not self.scan:
            logging.error("Failed scanning ")
            raise  unittest.SkipTest("Class setup failed skipping test")

        self.data = True
        if not self.data:
            logging.error("Failed getting data ")
            raise unittest.SkipTest("Class setup failed skipping test")
        logging.info("SETUP.....Done")

    def test_01_inode_scanion(self):
        """  test01: inode scanion """
        logging.info("### Executing test01:  ###")

    @classmethod
    def tearDownClass(self):
        """ Cleanup all the data & logs """
        logging.info("Cleaning all data")

def main():
    """ ---MAIN--- """

    try:
        unittest.main()
    except Exception as e:
        logging.exception(e)
        sys.exit(1)

if __name__ == '__main__':
    main()

Sample output
gpal-ae9703e-1# python unitest1.py
ERROR:root:Failed scanning
s
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK (skipped=1)

Regards,
Ganesh



More information about the Python-list mailing list