【发布时间】:2012-10-09 12:37:30
【问题描述】:
我正在做一些测试。我的一堆测试函数有共同的设置,所以我决定我应该使用来自nose.tools 的@with_setup 装饰器。我已将我的问题简化为:
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 根本没有运行。任何帮助将不胜感激!
【问题讨论】:
-
您知道您可以在您的
unittest.TestCase子类中定义setUp()来执行此操作吗?
标签: python unit-testing decorator nose