जब मैं अपने ऐप का परीक्षण कर रहा हूं तो मुझे फ्लास्क-एडमिन द्वारा ब्लूप्रिंट बनाने के साथ परेशानी हो रही है।परीक्षण के दौरान फ्लास्क-एडमिन ब्लूप्रिंट निर्माण
# flask-admin
admin.add_view(UserView(User, db.session))
admin.init_app(app)
हालांकि, जब मैं एक से अधिक परीक्षण (गलती हमेशा चलाने का प्रयास:
यह मेरा देखें वर्ग (SQLAlchemy का उपयोग कर)
##
# All views that only admins are allowed to see should inherit from this class.
#
class AuthView(ModelView):
def is_accessible(self):
return current_user.is_admin()
class UserView(AuthView):
column_list = ('name', 'email', 'role_code')
इस तरह मैं विचारों से प्रारंभ है दूसरे परीक्षण और अन्य सभी परीक्षणों का पालन करता है), मुझे हमेशा निम्न त्रुटि संदेश मिलता है:
======================================================================
ERROR: test_send_email (tests.test_views.TestUser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/lib/python2.7/site-packages/nose/case.py", line 133, in run
self.runTest(result)
File "/lib/python2.7/site-packages/nose/case.py", line 151, in runTest
test(result)
File "/lib/python2.7/site-packages/flask_testing.py", line 72, in __call__
self._pre_setup()
File "/lib/python2.7/site-packages/flask_testing.py", line 80, in _pre_setup
self.app = self.create_app()
File "/tests/test_init.py", line 27, in create_app
app = create_app(TestConfig)
File "/fbone/app.py", line 41, in create_app
configure_extensions(app)
File "/fbone/app.py", line 98, in configure_extensions
admin.add_view(UserView(User, db.session))
File "/lib/python2.7/site-packages/flask_admin/base.py", line 484, in add_view
self.app.register_blueprint(view.create_blueprint(self))
File "/lib/python2.7/site-packages/flask/app.py", line 62, in wrapper_func
return f(self, *args, **kwargs)
File "/lib/python2.7/site-packages/flask/app.py", line 885, in register_blueprint
(blueprint, self.blueprints[blueprint.name], blueprint.name)
AssertionError: A blueprint's name collision occurred between <flask.blueprints.Blueprint object at 0x110576910> and <flask.blueprints.Blueprint object at 0x1103bd3d0>. Both share the same name "userview". Blueprints that are created on the fly need unique names.
अजीब बात यह है कि यह केवल दूसरे परीक्षण पर होता है और कभी भी जब मैं ऐप चलाता हूं।
जब मैंने परीक्षणों को डीबग किया, पहली बार मैंने वही किया जो मैंने अपेक्षित किया और init_app (ऐप) के बाद ऐप में ब्लूप्रिंट जोड़ा। दूसरी बार हालांकि add_view चरण तक पहुंचने पर प्रक्रिया तुरंत बंद हो गई (जो मुझे लगता है कि अजीब है क्योंकि ब्लूप्रिंट इनिट_एप (एप) कॉल में पंजीकृत हो जाते हैं?)
जब आप कहते हैं कि "पहली बार" आपका पहला परीक्षण है या आप कह रहे हैं कि आपका यूनिट परीक्षण पूरा हो गया है और आप फिर से पूरे टेस्ट सूट चला रहे हैं। – AlexLordThorsen
मेरा मतलब है पहला टेस्ट – arnoutaertgeerts
सुनिश्चित करें कि आप प्रत्येक परीक्षण के लिए अपने एप्लिकेशन फैक्ट्री में 'Admin' क्लास का नया उदाहरण बनाएं। ऐसा लगता है कि आप प्रत्येक टेस्ट रन के लिए मौजूदा 'Admin' क्लास इंस्टेंस में दृश्य जोड़ते रहते हैं। – Joes