klenwell information services : PythonTemplateFunctionalTest

Python Functional Test Template

return to PythonTesting

This template reflects a straightforward unit test. With a little ingenuity, it can be adapted to most functional tests.

Code

#!/usr/bin/python

"""
    A Python Function Test Template
    Tom at klenwell@gmail.com
    some rights reserved, 2011

    Describe test here.
   
    Note: If you change test class name, be sure to update in main block at bottom.
"
""

#
# Imports
#
# Python Imports
import unittest, sys, os
from os.path import (abspath, dirname, join as osjoin, exists)
from datetime import(datetime, date, timedelta)
from random import (choice, sample)

# Extend sys.path
#basepath = abspath(osjoin(dirname(__file__), '../..'))
#sys.path.append(osjoin(basepath, 'bin'))



#
# Module Parameters
#
# Test Configuration
TEST_CONFIG = {
    'BREAK'             : False,
    'VERBOSE'           : False,
}

# Exception Classes



#
# Test Class
#
class FunctionalTest(unittest.TestCase):
   
    # Overhead
    def setUp(self):
        pass
   
    def tearDown(self):
        pass
   
   
    # Tests
    def testBreak(self):
        """Set BREAK property in TEST_CONFIG above to True to use Python
        debugger to break into test and interact from the command line"
""
        if TEST_CONFIG.get('BREAK'):
            import pdb; pdb.set_trace()
       
    def testInstance(self):
        """adapt to your purposes, I like to always include this as a sanity check"""
        self.assertTrue(isinstance(self, unittest.TestCase))
   
   
   
#
# Main
#
if __name__ == "__main__":
    mod = sys.modules[globals()['__name__']]
    suite = unittest.TestLoader().loadTestsFromModule(mod)
    unittest.TextTestRunner(verbosity=2).run(suite)