我正在做一些测试。我的一堆测试函数有共同的设置,所以我决定我应该使用@with_setup
来自nose.tools
. 我已将我的问题简化为:
from nose.tools import with_setup
class TestFooClass(unittest.TestCase):
def setup_foo_value(self):
self.foo = 'foobar'
@with_setup(setup_foo_value)
def test_something(self):
print self.foo
我收到以下错误:
$ python manage.py test tests/test_baz.py
E
======================================================================
ERROR: test_something (project.tests.test_baz.TestFooClass)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/user/Coding/project-backend/project/../project/tests/test_baz.py", line 17, in test_something
print self.foo
AttributeError: 'TestFooClass' object has no attribute 'foo'
----------------------------------------------------------------------
就像setup_foo_value
根本没有运行一样。任何帮助将非常感激!