Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101299
| From | Ganesh Pal <ganesh1pal@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | python unit test framework sample code |
| Date | 2016-01-06 19:15 +0530 |
| Message-ID | <mailman.28.1452087931.2305.python-list@python.org> (permalink) |
Hello Team,
I have written a small program using python unit test framework . I
need your guidance to find out
1. If I have used the fixtures and classes properly ( first oop program) :) )
2. why does unittest2.SkipTest not print the message when the failures
are encountered ?
3. Also sys.stderr.write("Test run failed ({e})".format(e=e) ) does
not display error on failure ?
4. Any other general comment's
Iam on Python 2.6 and using Linux
Sample code:
class FileSystemTest(unittest2.TestCase):
block_address = {}
report = ""
@classmethod
def setUpClass(cls):
cls.FileSystemSetup()
@classmethod
def FileSystemSetup(cls):
"""
Initial setup before unittest is run
"""
logging.info("SETUP.....Started !!!")
try:
inode_01 =
corrupt.get_lin(os.path.join(CORRUPT_DIR,"inode_lin.txt"))
test_01_log = os.path.join(LOG_DIR, "test_01_corrupt.log")
cls.block_address['test_01'] =
corrupt.inject_corruption(test_01_log,
lin=inode_01, object="inode", offset="18",
size="4", optype="set")
time.sleep(10)
except Exception, e:
logging.error(e)
raise unittest2.SkipTest("class setup failed")
if not corrupt.run_scanner():
raise unittest2.SkipTest("class setup failed")
else:
try:
cls.report = corrupt.run_report()
except Exception, e:
logging.error(e)
raise unittest2.SkipTest("class setup failed")
logging.info("SETUP.....Done !!!")
def inode_corruption(self):
""" test_01: inode corruption """
self.assertTrue(corrupt.run_query_tool(self.__class__.report,
self.block_address['test_01']))
@classmethod
def tearDownClass(cls):
cls.tearDown()
@classmethod
def tearDown(cls):
print "Entered tearDown()"
try:
cls.cleanup = cleanup()
except Exception, e:
logging.error(e)
def main():
""" ---MAIN--- """
global LOG_DIR
try:
if len(sys.argv) > 1:
LOG_DIR = str(sys.argv[1])
except Exception, e:
print(USAGE)
return errno.EINVAL
functions = [create_logdir,create_dataset,corrupt.prep_cluster]
for func in functions:
try:
func()
except Exception, e:
logging.error(e)
sys.stderr.write("Test run failed ({e})".format(e=e))
unittest2.main()
if __name__ == '__main__':
main()
PS : Happy New year Wishes to all the form members !!
Regards,
Ganesh
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
python unit test framework sample code Ganesh Pal <ganesh1pal@gmail.com> - 2016-01-06 19:15 +0530
csiph-web