Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101299
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | python unit test framework sample code |
| Date | Wed, 6 Jan 2016 19:15:22 +0530 |
| Lines | 96 |
| Message-ID | <mailman.28.1452087931.2305.python-list@python.org> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de ar42e/ErC8qo7KV1PbxX5wNqA/pbU35vdiAgB0Ap/LPA== |
| Return-Path | <ganesh1pal@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '"""': 0.05; '__name__': 0.07; 'main()': 0.07; 'subject:code': 0.07; 'subject:test': 0.07; 'unittest': 0.07; 'exception,': 0.09; 'func': 0.09; 'python': 0.10; 'def': 0.13; 'subject:python': 0.14; 'properly': 0.15; 'skip:f 30': 0.15; "'__main__':": 0.16; '@classmethod': 0.16; 'failed")': 0.16; 'main():': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 50': 0.16; 'subject:sample': 0.16; 'skip:l 30': 0.18; 'try:': 0.18; 'team,': 0.18; 'to:name:python-list@python.org': 0.20; 'written': 0.24; 'linux': 0.26; 'skip:" 20': 0.26; 'error': 0.27; 'message- id:@mail.gmail.com': 0.27; '2.6': 0.27; 'skip:u 20': 0.28; 'initial': 0.28; 'oop': 0.29; 'code:': 0.29; 'raise': 0.29; 'print': 0.30; 'classes': 0.30; 'skip:s 30': 0.31; 'run': 0.33; 'class': 0.33; 'except': 0.34; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'skip:s 60': 0.35; 'unit': 0.35; 'skip:i 20': 0.36; 'received:209.85': 0.36; 'framework': 0.36; 'guidance': 0.36; 'to:addr:python-list': 0.36; 'display': 0.37; 'received:209': 0.38; 'skip:o 20': 0.38; 'why': 0.39; 'test': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'sample': 0.63 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Wx6zv3Exco1yUiSUhQHQgz/WkFsmhx7YnhLzs2zRL08=; b=APkuRilQ4GXrSen4fFkbJR1NXrPzjX2lCrr24P12aIuMf3oso2Te6+cAYoIkYpcjQb TAALJ2MC/rzchzZmVcTHwsmRb+uFyamxhPZYwPfmXdVrQv5F4iwqdA0eEtvEpBmm2/SJ D4YhB3Cz0Y959AlOMe7huXXF3BOTM83YwyCs7y2d1gHgcKYxKNt5Pb173ia2z+R4NPJR Bk02a1XQzaOdwWvwxSBMJHI2nd0rcXFeDA8r49hO+G51iyLFpJqSeTxV5I1q/31Unukk idmj++T9tzQM5w4E7gPRfxIvlkysGML874mABE7GDXX/uKca988G2gE9AmnKT7W9DndZ HAdA== |
| X-Received | by 10.25.27.16 with SMTP id b16mr27640282lfb.149.1452087922329; Wed, 06 Jan 2016 05:45:22 -0800 (PST) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:101299 |
Show key headers only | View raw
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