Skip to content

Instantly share code, notes, and snippets.

@premchalmeti
Last active August 28, 2021 17:23
Show Gist options
  • Save premchalmeti/06c3484e10d69bdf21c07f02827bdf10 to your computer and use it in GitHub Desktop.
Save premchalmeti/06c3484e10d69bdf21c07f02827bdf10 to your computer and use it in GitHub Desktop.
The python's unittest library executes the tests in alphabetical order to override this behaviour and execute tests in (defined) order. Use `unittest.main(testLoader=SequentialTestCaseLoader())` to trigger execution.
import unittest
class SequentialTestCaseLoader(unittest.TestLoader):
"""
The python's unittest library executes the tests in alphabetical order
to override this behaviour and execute tests in (defined) order.
Use `unittest.main(testLoader=SequentialTestCaseLoader())` to
the trigger execution.
"""
def getTestCaseNames(self, tcCls):
tcnames = super().getTestCaseNames(tcCls)
tc_mtds = list(tcCls.__dict__.keys())
tcnames.sort(key=tc_mtds.index)
return tcnames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment