Run setUp only once for a set of automated tests

前端 未结 8 1251
逝去的感伤
逝去的感伤 2020-12-13 05:15

My Python version is 2.6.

I would like to execute the test setUp method only once since I do things there which are needed for all tests.

My idea was to crea

8条回答
  •  不知归路
    2020-12-13 06:14

    If you ended up here because of need to load some data for testing... then as far as you are using Django 1.9+ please go for setUpTestData:

    class MyTests(TestCase):
    
        @classmethod
        def setUpTestData(cls):
            # Set up data for the whole TestCase
            cls.foo = Foo.objects.create(bar="Test")
    
        def test1(self):
            self.assertEqual(self.foo.bar, 'Test') 
    

提交回复
热议问题