Unittest tests order

后端 未结 19 1283
刺人心
刺人心 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:48

    You can disable it by setting sortTestMethodsUsing to None: http://docs.python.org/2/library/unittest.html#unittest.TestLoader.sortTestMethodsUsing

    import unittest
    unittest.TestLoader.sortTestMethodsUsing = None
    

    For pure unittests, you folks are right; but for component tests and integration tests... I do not agree that you shall assume nothing about the state. What if you are testing the state. For example, your test validates that a service is auto-started upon installation. If in your setup, you start the service, then do the assertion, then you are no longer testing the state but you are testing the "service start" functionality.

    Another example is when your setup takes a long time or requires a lot of space and it just becomes impractical to run the setup frequently.

    Many developers tend to use "unittest" frameworks for component testing...so stop and ask yourself, am I doing unittesting or component testing.

提交回复
热议问题