Skip to content

Instantly share code, notes, and snippets.

@gahcep
Created February 10, 2013 13:34
Show Gist options
  • Save gahcep/4749600 to your computer and use it in GitHub Desktop.
Save gahcep/4749600 to your computer and use it in GitHub Desktop.
Article 'QA in Python - working with unittest'
import unittest
def setUpModule():
print "In setUpModule()"
def tearDownModule():
print "In tearDownModule()"
class FirstTestClass(unittest.TestCase):
'''
Invoked without setUp and tearDown methods
'''
def test_add(self):
print "In test_add()"
self.assertEquals(120, 100 + 20)
class SecondTestClass(unittest.TestCase):
'''
Invoked with setUpClass/setUp and tearDown/tearDownClass methods
'''
@staticmethod
def setUpClass():
print "In setUpClass()"
def setUp(self):
print "In setUp()"
def test_sub(self):
print "In test_sub()"
self.assertEquals(210, 110 * 2 - 10)
self.assertEquals(170, 140 - (-30))
def test_mul(self):
print "In test_mul()"
self.assertEquals(420, 210 * 2)
self.assertEquals(420, 210 * 2.0000000000000000000001)
def tearDown(self):
print "In tearDown()"
@staticmethod
def tearDownClass():
print "In tearDownClass()"
if __name__ == '__main__':
unittest.main()
# CLI run options
# - pyexample_3.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment