Update to Django 1.8 - AttributeError: django.test.TestCase has no attribute 'cls_atomics'

后端 未结 4 1278
既然无缘
既然无缘 2021-02-11 11:41

I updated a Django 1.7 project to Django 1.8 and now get errors when I run the tests (that are subclasses of django.test.TestCase).

Traceback (most          


        
4条回答
  •  心在旅途
    2021-02-11 12:22

    For Django 1.8+, you should use TestCase.setUpTestData instead of TestCase.setUpClass.

    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') 
    

    The documentation is here.

提交回复
热议问题