class MotherTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.my_value = "foo"
class ChildTestCase(MotherTestCase):
def test_basic(self):
self.assertEqual(self.my_value, "foo")
当运行这个测试时,我得到一个AttributeError: 'ChildTestCase' object has no attribute 'my_value'
你怎么解释?我认为我需要调用super()
,但是{a1}没有这么说
我在Github上看到了一个related issue,但它已经有一年的历史了,似乎已经修复了。在
注意:我使用的是python3.5.2和Django 1.9.10
这有点令人困惑,但是有两个不同的
TestCase
类。有unittest.TestCase
,还有Django测试用例类django.test.TestCase
。为了使其工作,必须从django.test
导入,而不是从unitttest导入。在相关问题 更多 >
编程相关推荐