Reputation: 1933
I'm using python unittest frame work for do some testing.
class AbstractTest(unittest.TestCase):
def setUp(self):
def tearDown(self):
# Close!
self.transport.close()
def testVoid(self):
self.client.testVoid()
def testString(self):
global test_basetypes_fails
try:
self.assertEqual(self.client.testString('Python' * 20), 'Python' * 20)
except AssertionError, e:
test_basetypes_fails = True
print test_basetypes_fails
raise AssertionError( e.args )
try:
self.assertEqual(self.client.testString(''), '')
except AssertionError, e:
test_basetypes_fails = True
raise AssertionError( e.args )
def testByte(self):
global test_basetypes_fails
try:
self.assertEqual(self.client.testByte(63), 63)
except AssertionError, e:
test_basetypes_fails = True
raise AssertionError( e.args )
try:
self.assertEqual(self.client.testByte(-127), -127)
except AssertionError, e:
test_basetypes_fails = True
raise AssertionError( e.args )
@classmethod
def tearDownClass(cls):
#sys.exit(1)
When I execute my test I am getting following result.
..................
----------------------------------------------------------------------
Ran 18 tests in 2.715s
OK
I need to execute a piece of program after this finishes execution. How can I do that? When I add code to class level tear down it executes it after following part of output is made.
..................
Upvotes: 2
Views: 722
Reputation: 6395
You need to write your own testrunner, so that you can return with an exit-code depending on the result of the suite.
All you need to do is explained in the unittest-module documentation. Use a TestLoader to load your suite, and a TextTestRunner to run it. Then depending on the result of the suite, call sys.exit with your appropriate exit-code.
Upvotes: 2