2

Pyramid プロジェクトの 1 つにテスト ファイルがあります。6 つのテストを含む1 つのスイートがあります。

...
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.pytemplates.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、出力は期待どおり OK です。

......
----------------------------------------------------------------------
Ran 6 tests in 1.980s

OK

出力が異なるのはなぜですか? また、余分な (7 回目の) テストが実行されるのはなぜですか?

アップデート。少しイライラしますが、名前からテストpopulate_test_dataという単語を削除すると( になりましたpopulate_dummy_data)、すべて正常に機能しました。

問題は今のところ解決されていますが、おそらく誰かがここで何がうまくいかなかったのかを知っているかもしれません-なぜ関数setUpがテストされたのですか?

4

1 に答える 1