I have a plotly dash app defined in 2 files:
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)
Now, When I try to run more then one test using import_app,
tests\test_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 (...)
I get an error on scenario 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.
How to run these two scenarios without an error? Is this a right approach for Plotly Dash App multiple tests?
I have posted the same issue here: