更新到Django 1.8 - AttributeError:django.test.TestCase没有属性'cls_atomics' [英] Update to Django 1.8 - AttributeError: django.test.TestCase has no attribute 'cls_atomics'
问题描述
django.test.TestCase
的子类)时,会收到错误。 追溯(最近最近通话):
文件env\lib\site-packages\django\test\\ \\ testcases.py,第962行,在tearDownClass
cls._rollback_atomics(cls.cls_atomics)
AttributeError:类型对象'SomeTests'没有属性'cls_atomics'
如果我通过测试进行调试,我可以无障碍地遍历所有行,但在最后一行之后抛出异常。
这是一个示例测试:
import django
import unittest
from django.test import TestCase
import logging
import sys
from builtins import classmethod,isinstance
class ATestTests(TestCase):
@classmethod
def setUpClass(cls):
django.setup()
logging.basicConfig(s tream = sys.stderr,level = logging.DEBUG)
def setUp(self):
self._app = Application(name =a)
def testtest(self):
self.assertIsNotNone(self._app)
我的环境:
astroid == 1.3.4
colorama == 0.3 .3
defusedxml == 0.4.1
Django == 1.8
django-extensions == 1.5.2
django-filter == 0.9.2
djangorestframework = = 3.0.5
djangorestframework-xml == 1.0.1
eight == 0.3.0
future == 0.11.4
logilab-common == 0.63.2
Markdown == 2.5.2
pylint == 1.4.1
python-dateutil == 2.4.1
python-mimeparse == 0.1.4
six == 1.9 .0
xmltodict == 0.9.2
我如何解决这个问题? >
我相信原因是您的 setUpClass(cls)
类方法不叫超级因此, django.tests.TestCase.setUpClass
未调用,
cls.cls_atomics = cls._enter_atomics()
未被调用,自然会导致<$ c $您应该添加 super(ATestTests,cls).setUpClass()
code>到您的 setUpClass
。
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 recent call last):
File "env\lib\site-packages\django\test\testcases.py", line 962, in tearDownClass
cls._rollback_atomics(cls.cls_atomics)
AttributeError: type object 'SomeTests' has no attribute 'cls_atomics'
If I debug through the test I can step through all lines without problems, but after the last line the exception is thrown.
This is an example test:
import django
import unittest
from django.test import TestCase
import logging
import sys
from builtins import classmethod, isinstance
class ATestTests(TestCase):
@classmethod
def setUpClass(cls):
django.setup()
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
def setUp(self):
self._app = Application(name="a")
def testtest(self):
self.assertIsNotNone(self._app)
My environment:
astroid==1.3.4
colorama==0.3.3
defusedxml==0.4.1
Django==1.8
django-extensions==1.5.2
django-filter==0.9.2
djangorestframework==3.0.5
djangorestframework-xml==1.0.1
eight==0.3.0
future==0.11.4
logilab-common==0.63.2
Markdown==2.5.2
pylint==1.4.1
python-dateutil==2.4.1
python-mimeparse==0.1.4
six==1.9.0
xmltodict==0.9.2
How can I fix this?
I believe the reason is that your setUpClass(cls)
class method is not calling super. Because of that, django.tests.TestCase.setUpClass
is not called and
cls.cls_atomics = cls._enter_atomics()
is not called, naturally causing cls_atomics
to be undefined.
You should add super(ATestTests, cls).setUpClass()
to your setUpClass
.
这篇关于更新到Django 1.8 - AttributeError:django.test.TestCase没有属性'cls_atomics'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!