-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
dash 2.1.0
dash-bootstrap-components 1.0.3
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table 5.0.0
pytest 7.0.1
Describe the bug
It seems that dash testing utils don't work property with All-in-One components. For instance, given the following test scenario:
import uuid
from typing import Optional
import dash
from dash import MATCH, Input, Output, callback, html
class SomeButton(html.Button):
class ids:
button = lambda aio_id: {"component": "SomeButton", "aio_id": aio_id}
def __init__(self, aio_id: Optional[str] = None):
if aio_id is None:
aio_id = str(uuid.uuid4())
super().__init__(
"Loading...",
id=self.ids.button(aio_id),
disabled=True,
)
@callback(
Input(ids.button(MATCH), "children"),
output=dict(
label=Output(ids.button(MATCH), "children"),
disabled=Output(ids.button(MATCH), "disabled"),
),
)
def update_button(_):
return dict(label="Loaded", disabled=False)
def test_some_button_first_time(dash_duo: dash.testing.composite.DashComposite):
app = dash.Dash("foo123")
app.layout = html.Div(SomeButton(), id="wrapper")
dash_duo.start_server(app)
dash_duo.wait_for_contains_text("#wrapper", "Loaded")
def test_some_button_second_time(dash_duo: dash.testing.composite.DashComposite):
app = dash.Dash("bar123")
app.layout = html.Div(SomeButton(), id="wrapper")
dash_duo.start_server(app)
dash_duo.wait_for_contains_text("#wrapper", "Loaded")
The first run test_some_button_first_time
is perfectly fine. But test_some_button_second_time
results with selenium.common.exceptions.TimeoutException: Message: text -> Loaded not found inside element within 10s
error.
I ran it with --pause
option and in the DevTools I noticed that for the second test the update callback _dash-update-component
is not being triggered (see the attached screenshots).
Moreover, if I run test_some_button_second_time
separately or if I comment out the first test everything is fine.
For some reason callbacks are fired only for the first test.
Expected behavior
It seems that dash_duo
does not work with @callback
for all-in-one components.
Screenshots