Python unittest2.SkipTest and general suggestion

Ganesh Pal ganesh1pal at gmail.com
Sun Feb 21 10:57:31 EST 2016


Hello team,

Please provide your guidance on how to proceed with the below test  ,
Iam on python 2.6 and Linux. I have a linitation to use python 2.6 and
unittest2


try:
    import unittest2 as unittest
except ImportError:
    import unittest

class isiCorruptTest(unittest.TestCase):

    corrupt_baddr = {}
    report=  ""
    @classmethod
    def setUpClass(cls):
        cls.corruptSetup()

    @classmethod
    def corruptSetup(cls):
        """
        Initial setup before unittest run
        """
        logging.info("SETUP.....Started !!!")
        try:
            logging.info("Capturing data as part of prechecks for test_xx")
            capture_data()
        except Exception as e:
            logging.error(e)
            sys.exit("Corruption injection failed...Exiting !!!")

        try:
            corrupt.run_scan()
        except Exception as e:
            logging.error(e)
            raise unittest.SkipTest("Failure running Integrity Scan ")

        try:
            cls.report = corrupt.run_report()
        except Exception as e:
            logging.error(e)
            raise unittest.SkipTest("Failure running Reporting Tool ")
            #sys.exit(1)

        logging.info("SETUP.....Done !!!")

    def test_04_inode(self):
        """ test04:  """
        logging.info("### Executing test04: ###")
        self.assertTrue(corrupt.run_query(self.__class__.report,
                                               self.corrupt_baddr['test04']))


def main():
    """ ---MAIN--- """
    # both function are not shown in this code
    functions = [create_logdir, create_dataset ]
    for func in functions:
        try:
            func()
        except Exception as e:
            logging.error(e)
            return False
    unittest.main()

if __name__ == '__main__':
    main()

I have the below problems while running this code:

1.  unittest.SkipTest does not the display the  exception message that
is caught.

Example : The function corrupt.run_scan() returns none and False for failures


3.  how do I the ensure that test_04 is run only it setUpClass succeeds ?

Example: Iam getting this  error message for each tests on the console.


======================================================================
ERROR: test_04_inode (__main__.isiCorruptTest)
test04: inode offset, size corruption
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c_t1.py", line 251, in test_04_inode_offset_size_corruption
    self.corrupt_baddr['test04']))
KeyError: 'test04'


3.  Any other suggestion welcome


Regards,
Ganesh


More information about the Python-list mailing list