plotly / plotly/dash

provide `typing.Protocol` for `dash_duo`

Open
#2,170 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature P3
Dominant language
Python
Stars
24.4k
Forks
2.3k
Avg merge
2d 7h
Merged PRs (30d)
13

Description

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

Screen Shot 2022-07-27 at 11 11 43

Describe alternatives you've considered

None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the dash.testing.plugin.dash_duo fixture and inspect the methods and signatures it exposes, including start_server and find_element. Define a typing.Protocol that represents those fixture methods and verify that annotating a pytest test with it provides the requested method signatures and autocomplete support.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.