-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyunit.py
43 lines (29 loc) · 1.19 KB
/
pyunit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
import xmlrunner
class SimpleTestCase(unittest.TestCase):
def setUp(self):
"""Call before every test case."""
def tearDown(self):
"""Call after every test case."""
def testA(self):
"""Test case A. note that all test method names must begin with 'test.'"""
assert 0x21F == 543, "bar() not calculating values correctly"
def testB(self):
"""test case B"""
assert 23 + 12 == 35, "can't add Foo instances"
def testC(self):
"""test case C"""
assert "blah" == "blah", "baz() not returning blah correctly"
class OtherTestCase(unittest.TestCase):
def setUp(self):
self.blahblah = "blah"
def testBlah(self):
assert self.blahblah == "blah", "blah isn't blahing blahing correctly"
if __name__ == "__main__":
testRunner = xmlrunner.XMLTestRunner(output=".")
simpleSuite = unittest.defaultTestLoader.loadTestsFromTestCase(SimpleTestCase)
otherSuite = unittest.defaultTestLoader.loadTestsFromTestCase(OtherTestCase)
success = True
success &= testRunner.run(simpleSuite).wasSuccessful()
success &= testRunner.run(otherSuite).wasSuccessful()
exit(0 if success else 1)