Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100237
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ganesh Pal <ganesh1pal@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | python unit test frame work |
| Date | Thu, 10 Dec 2015 20:29:57 +0530 |
| Lines | 119 |
| Message-ID | <mailman.114.1449759605.12405.python-list@python.org> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de Spz1tvN9toEseoX8+If/gAl+XqJGGIrbvL0B8epuoCwA== |
| 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; 'error:': 0.05; 'tries': 0.05; '__name__': 0.07; 'cleanup': 0.07; 'executed': 0.07; 'main()': 0.07; 'skip:/ 10': 0.07; 'subject:test': 0.07; '-rf': 0.09; 'exception,': 0.09; 'example:': 0.10; 'skip:= 70': 0.10; 'python': 0.10; '2.7': 0.13; 'def': 0.13; 'subject:python': 0.14; "'__main__':": 0.16; 'failed")': 0.16; 'i.e': 0.16; 'main():': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'setup(self):': 0.16; 'sys.exit(1)': 0.16; 'unittests': 0.16; 'xxx,': 0.16; "shouldn't": 0.18; 'skip:l 30': 0.18; 'test.': 0.18; 'try:': 0.18; 'team,': 0.18; 'tests': 0.18; 'to:name:python-list@python.org': 0.20; 'fix': 0.21; 'keyerror:': 0.22; 'trying': 0.22; '(most': 0.24; 'skip:" 20': 0.26; 'error': 0.27; 'message-id:@mail.gmail.com': 0.27; 'appreciated': 0.27; 'executing': 0.27; 'idea': 0.28; 'initial': 0.28; 'reporting': 0.29; 'starts': 0.29; 'code': 0.30; 'error.': 0.31; 'skip:s 30': 0.31; 'run': 0.33; 'class': 0.33; 'traceback': 0.33; 'file': 0.34; 'except': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'false': 0.35; 'comment': 0.35; 'unit': 0.35; 'tool': 0.36; 'received:209.85': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'skip:s 50': 0.37; 'received:209': 0.38; 'skip:o 20': 0.38; 'end': 0.39; 'test': 0.39; 'data': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'questions': 0.40; 'skip:u 10': 0.61; 'avoid': 0.61; 'sample': 0.63; 'here': 0.66 |
| 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=zK7eqIixfcftAoaxRgn0Drdvpe2cP6FyePts4vxjwu4=; b=U/uXalggUDz/h7RATaenGCkiiSB5yIAuNnQXj5VSo//87js1r8u+9XupO/Gs80LgSl xH6uG8ETNaJAcst3iCxrIyHnVxadtQxAyPsLambkIyds+5RptTSqFcpaTxNiJhcOUmNA xE+4HmVkJQbkasC4ZM3yHDjvtbtMufNoznCeb1KkiJ2X2cvZTBmKesneXGq4Rfbb4P+l M1OiLdE4GDNOI4wFmldL7qMdP5sOHl1Pvq5DTTT04aFkoAV0u3UgLgsVhn1tHNMA+485 W1dhx8R7VMm78eaRrouQvpcR6/17l780IadpBdLTlGwXW94cJhMc2M7KOTpogM9eZc8C iBIA== |
| X-Received | by 10.25.144.65 with SMTP id s62mr4621446lfd.104.1449759597679; Thu, 10 Dec 2015 06:59:57 -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:100237 |
Show key headers only | View raw
Hello Team,
Iam on python 2.7 and linux. Iam trying to understand the python unit
test frame work and also trying to fix the below code , any help in
this regard would be appreciated ?
# Sample code starts here
inject_failure = {}
report = ""
ClassIsSetup = False
ClassCleanup = False
class Test_filesystem(unittest.TestCase):
""" """
def TestSetup(self):
""" Initial setup before unittests run """
logging.info("SETUP.....Started !!!")
if not os.path.ismount("/tmp"): # Comment 1.
logging.error("Error: /tmp is not mounted")
sys.exit("/tmp is not mounted ...Exiting !!!")
if self.create_dataset() and capture_chksum():
try:
test01_log = os.path.join(LOG_DIR, "test01_corrupt.log")
self.inject_failure['test01'] = tool.run_tool(test01_log)
time.sleep(10)
test02_log = os.path.join(LOG_DIR, "test01_corrupt.log")
self.inject_failure['test01'] = tool.run_tool(test02_log)
time.sleep(10)
except Exception, e:
logging.error(e)
sys.exit(1)
if not run_scanner():
sys.exit(1)
else:
try:
self.__class__.report = report_tool()
except Exception, e:
logging.error(e)
sys.exit("Running Reporting tool failed")
logging.info("SETUP.....Done !!!")
def setUp(self):
if not self.ClassIsSetup:
self.__class__.ClassIsSetup = True
self.setupClass()
def setupClass(self):
self.TestSetup()
def test_01_inode_test(self):
""" test01: """
logging.info("### Executing test01: inode corruption ###")
self.assertTrue(run_db_tool(self.__class__.report,
self.find_failure['test01']))
def test_02_hardlink_test(self):
""" test02: """
logging.info("### Executing test01: inode corruption ###")
self.assertTrue(run_db_tool(self.__class__.report,
def tearDown(self):
if self.ClassCleanup:
self.tearDownClass()
def tearDownClass(self):
self.cleanup()
# Comment 2
def cleanup(self):
""" Cleanup all the data & logs """
logging.info("Cleaning all data")
os.system("rm -rf /tmp/data_set")
def main():
unittest.main()
if __name__ == '__main__':
main()
# Sample code ends here
Questions :
1. If the setUp() fails the code still tries to run through the test
and assert's with error. How do I avoid these Error on the console ,
actually test01, test02, . etc , shouldn't run if the setup Failed ?
Example: If the mount fails i.e if not os.path.ismount("/tmp"): in
TestSetup(). we will get the below output:
#c_t.py
EEEE
======================================================================
ERROR: test01: test_01_inode_test
----------------------------------------------------------------------
Traceback (most recent call last):
File "c_t.py", line xx, in setUp
self.setupClass()
File "c_t.py", line xxx, in TestSetup
self.TestSetup()
File "c_t.py", line xx, in corruptSetup
sys.exit("/tmp is not mounted ...Exiting !!!")
SystemExit: /tmp is not mounted ...Exiting !!!
======================================================================
ERROR: test02
----------------------------------------------------------------------
Traceback (most recent call last):
File "c_t.py", line 162, in test_02_hardlink_test
self.inject_failures['test02']))
KeyError: 'test02'
Ran 2 tests in 0.003s
FAILED (errors=2)
2. The cleanup() never gets executed at the end of the test.
3. Any better idea or suggestions to improve the above code ?
Regards,
Ganesh
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
python unit test frame work Ganesh Pal <ganesh1pal@gmail.com> - 2015-12-10 20:29 +0530
csiph-web