# encoding=utf8
"""一个unittest的demo,按函数声明的顺序执行测试用例
"""
import unittest
class TestOrder(unittest.TestCase):
def test_b(self):
print 'test_b success'
def test_a(self):
print 'test_a success'
if __name__ == '__main__':
loader = unittest.TestLoader()
def ln(f):
return getattr(TestOrder, f).im_func.func_code.co_firstlineno
loader.sortTestMethodsUsing = lambda a, b: cmp(ln(a), ln(b))
test_suite1 = loader.loadTestsFromTestCase(TestOrder)
test_suites = unittest.TestSuite([test_suite1])
test_runner = unittest.TextTestRunner(verbosity=2)
test_runner.run(test_suites)
网友评论