我的 Pyramid 项目之一中有一个测试文件。它有一套包含六个测试的套件:
...
from .scripts import populate_test_data
class FunctionalTests(unittest.TestCase):
def setUp(self):
settings = appconfig('config:testing.ini',
'main',
relative_to='../..')
app = main({}, **settings)
self.testapp = TestApp(app)
self.config = testing.setUp()
engine = engine_from_config(settings)
DBSession.configure(bind=engine)
populate_test_data(engine)
def tearDown(self):
DBSession.remove()
tearDown()
def test_index(self):
...
def test_login_form(self):
...
def test_read_recipe(self):
...
def test_tag(self):
...
def test_dish(self):
...
def test_dashboard_forbidden(self):
...
现在,当我运行时nosetests templates.py
(templates.py
提到的文件在哪里),我得到以下输出:
......E
======================================================================
ERROR: templates.populate_test_data
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yentsun/env/local/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/yentsun/env/local/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg/nose/util.py", line 622, in newfunc
return func(*arg, **kw)
TypeError: populate_test_data() takes exactly 1 argument (0 given)
----------------------------------------------------------------------
Ran 7 tests in 1.985s
FAILED (errors=1)
当我使用指定的测试套件运行测试时nosetests templates.py:FunctionalTests
,输出如预期的那样正常:
......
----------------------------------------------------------------------
Ran 6 tests in 1.980s
OK
为什么我有不同的输出以及为什么要运行额外的(第 7 次)测试?
更新。这有点令人沮丧,但是当我从名称中删除单词testpopulate_test_data
时(它变成了populate_dummy_data
),一切正常。
现在问题已经解决了,但也许有人知道这里出了什么问题——为什么一个函数setUp
已经被测试了?