Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- import unittest
- class SortTest(unittest.TestCase):
- def test_one(self): print("none: " + str(datetime.datetime.now().time()))
- def test_two(self): print("ntwo: " + str(datetime.datetime.now().time()))
- def test_three(self): print("nthree: " + str(datetime.datetime.now().time()))
- def test_four(self): print("nfour: " + str(datetime.datetime.now().time()))
- def test_five(self): print("nfive: " + str(datetime.datetime.now().time()))
- def test_six(self): print("nsix: " + str(datetime.datetime.now().time()))
- def suiteFactory(*test_cases):
- ln = lambda f: getattr(tc, f).__code__.co_firstlineno
- lncmp = lambda a, b: ln(a) - ln(b)
- test_suite = unittest.TestSuite()
- for tc in test_cases:
- test_suite.addTest(unittest.makeSuite(tc, sortUsing=lncmp))
- return test_suite
- def caseFactory():
- from inspect import findsource
- g = globals().copy()
- cases = [
- g[obj] for obj in g
- if obj.startswith("Test")
- and issubclass(g[obj], unittest.TestCase)
- ]
- ordered_cases = sorted(cases, key=lambda f: findsource(f)[1])
- return ordered_cases
- if __name__ == '__main__':
- cases = suiteFactory(*caseFactory())
- runner = unittest.TextTestRunner(verbosity=2)
- runner.run(cases)
Add Comment
Please, Sign In to add comment