dash
dash copied to clipboard
[Feature Request] `typing.Protocol` for `dash_duo`
Is your feature request related to a problem? Please describe.
The DX for using the pytest fixture dash.testing.plugin.dash_duo() could be improved by providing a typing.Protocol to type hint available methods and their signatures.
Describe the solution you'd like
from typing import Protocol
import dash
from dash.testing.application_runners import import_app
from dash.testing.wait import wait_for_element_by_css_selector, wait_for_text_to_equal
class DashDuo(Protocol):
"The dash_duo pytest fixture lives in dash.testing.plugin.dash_duo."
def start_server(self, start_server) -> None:
...
def find_element(self, selector: str) -> dash.development.base_component.Component:
...
def test_example_app(dash_duo: DashDuo): # type hint for dash_duo enables auto-complete
app = import_app("example")
dash_duo.start_server(app)
my_component = dash_duo.find_element("#hello-world")
assert "my-value" == my_component.get_attribute("value")
....
Screenshot from VS Code showing auto-complete in action

Describe alternatives you've considered
None
Seems reasonable, @T4rk1n you've worked on typing for dash.testing a bit, any thoughts? Will it be possible to have this picked up automatically by VSCode when dash_duo is used as a pytest fixture, or will you still need to import a DashDuo and annotate every dash_duo?
You would have to annotate every single use of dash_duo unless you had some extension like pytest-fixtures installed.
Pycharm pick it up by default, not a vscode user so I don't know about it, but seems like the plugin would work?
I made a rough start over here if you want to pick up from that. Or maybe DashDuo can be auto-generated?
Hi this sounds interesting. Happy to pick it up with some guidance. Thanks.