我在两个文件中定义了一个plotly dash应用程序:
app.py
from flask import Flask
import dash
import dash_bootstrap_components as dbc
server = Flask(__name__)
app = dash.Dash(name='MYAPP', external_stylesheets=[dbc.themes.BOOTSTRAP])
app.title = 'MYAPP'
app.config.suppress_callback_exceptions = True
index.py
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from flask import session
from app import app
srv = app.server
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content'),
])
@app.callback(Output('page-content', 'children'),
[Input('url', 'pathname'),
Input('url', 'hash'),])
def display_page(p_pathname, p_hash):
# Some logic to serve different pages
# (...)
if __name__ == '__main__':
app.run_server(processes=1, debug=True, threaded=True)
现在,当我尝试使用import_app运行多个测试时
tests\test\u something.py
from dash.testing.application_runners import import_app
def test_scenario_1(dash_duo):
app = import_app('index')
dash_duo.start_server(app)
dash_duo.wait_for_element_by_id('page-content', timeout=30)
# do some tests (...)
def test_scenario_2(dash_duo):
app = import_app('index')
dash_duo.start_server(app)
# do other tests (...)
我在场景2中遇到一个错误:
dash.exceptions.DuplicateCallbackOutput:
You have already assigned a callback to the output
with ID "page-content" and property "children". An output can only have
a single callback function. Try combining your inputs and
callback functions together into one function.
如何在没有错误的情况下运行这两个场景?这是Plotly Dash应用程序多个测试的正确方法吗
目前没有回答
相关问题 更多 >
编程相关推荐