Last active
August 28, 2021 17:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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