Test test_remove need to be the first test and not a second.
I try to cancel the alphabet sort of unittest (use sortTestMethodsUsing ) but I still have the problem to order my test.
The problem is that I need to run 2 functions that can help me with my problem in another file. I asked from the user that create this solution but the problem is that he still not answer to me. Maybe you know how can I do that?
Thank you!!!
in python unittest framework, according to it’s help doc,you can see sentences like this:
Note:
The order in which the various tests will be run is determined by sorting the test method names with respect to the built-in ordering for strings.
this means you can start your testcase name with nums or letters to help you control which runs first. just like this:
def test_1_casename:
pass
def test_2_casename:
pass
sorry, i don’t understand why you have to update the whole index when you change you test case.
if you add a case, plus one num or choose a bigger letter according to your prior case name ,
if you remove one, the former case name always smaller than the latter ,it won’t make any influence, so , what’s the problem.
import unittest
unittest.TestLoader.sortTestMethodsUsing = lambda self, a, b: (a < b) - (a > b)
class TestStringMethods(unittest.TestCase):
def test_remove(self):
print("1")
def test_add(self):
print("2")
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestStringMethods)
unittest.TextTestRunner(verbosity=2).run(suite)