我有我的 Flask 应用程序,它使用 Flask-Assets 并且在尝试运行单元测试用例时,除了第一个测试用例之外,其他用例失败并出现以下 RegisterError。
======================================================================
ERROR: test_login_page (tests.test_auth.AuthTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/cnu/env/flenv/lib/python2.7/site-packages/nose/case.py", line 133, in run
self.runTest(result)
File "/Users/cnu/env/flenv/lib/python2.7/site-packages/nose/case.py", line 151, in runTest
test(result)
File "/Users/cnu/env/flenv/lib/python2.7/site-packages/flask_testing.py", line 72, in __call__
self._pre_setup()
File "/Users/cnu/env/flenv/lib/python2.7/site-packages/flask_testing.py", line 80, in _pre_setup
self.app = self.create_app()
File "/Users/cnu/Projects/Bookworm/App/tests/test_auth.py", line 8, in create_app
return create_app('testing.cfg')
File "/Users/cnu/Projects/Bookworm/App/bookworm/__init__.py", line 118, in create_app
configure_extensions(app)
File "/Users/cnu/Projects/Bookworm/App/bookworm/__init__.py", line 106, in configure_extensions
assets.register('js_all', js)
File "/Users/cnu/env/flenv/src/webassets/src/webassets/env.py", line 374, in register
'as "%s": %s' % (name, self._named_bundles[name]))
RegisterError: Another bundle is already registered as "js_all": <Bundle output=assets/packed.js, filters=[<webassets.filter.jsmin.JSMin object at 0x10fa8af90>], contents=('js/app.js',)>
我对为什么会在第一个测试用例运行之前发生这种情况的理解,create_app 创建了一个 app 实例,并为所有其他测试用例维护。
我尝试del(app)
了拆卸方法,但没有帮助。
有什么办法可以解决吗?