Unittest tests order

后端 未结 19 1307
刺人心
刺人心 2020-12-01 03:17

How do I be sure of the unittest methods order? Is the alphabetical or numeric prefixes the proper way?

class TestFoo(TestCase):
    def test_1(self):
               


        
19条回答
  •  悲&欢浪女
    2020-12-01 03:49

    I have implemented a plugin nosedep for Nose which adds support for test dependencies and test prioritization.

    As mentioned in the other answers/comments this is often a bad idea, however there can be exceptions where you would want to do this (in my case it was performance for integration tests - with a huge overhead for getting into a testable state, minutes vs hours).

    A minimal example is:

    def test_a:
      pass
    
    @depends(before=test_a)
    def test_b:
      pass
    

    To ensure that test_b is always run before test_a.

提交回复
热议问题