Skip to main content

pytest fixtures to run dash app.

Project description


Pytest fixtures for dash.


$ pip install pytest-dash



Start a dash instance in a thread, stop the server in teardown. Use this if you need to count how many times a callback was fired.

import dash

import dash_html_components as html

from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate

from pytest_dash.utils import wait_for_element_by_css_selector
from pytest_dash.utils import wait_for_text_to_equal

def test_app(dash_threaded, selenium):
    app = dash.Dash(__name__)
    counts = {'clicks': 0}
    app.layout = html.Div([
        html.Div('My test layout', id='out'),
        html.Button('click me', id='click-me')
    @app.callback(Output('out', 'children'), [Input('click-me', 'n_clicks')])
    def on_click(n_clicks):
        if n_clicks is None:
            raise PreventUpdate
        counts['clicks'] += 1
        return 'Clicked: {}'.format(n_clicks)
    btn = wait_for_element_by_css_selector(selenium, '#click-me')
    wait_for_text_to_equal(selenium, '#out', 'Clicked: 1')
    assert counts['clicks'] == 1



Start an app instance contained in a module with waitress-serve in a subprocess. Kill the process in teardown.

from pytest_dash.utils import wait_for_text_to_equal

def test_subprocess(dash_subprocess, selenium):

    value_input = selenium.find_element_by_id('value')
    value_input.send_keys('Hello dash subprocess')

    wait_for_text_to_equal(selenium, '#out', 'Hello dash subprocess')


Helper methods.

  • wait_for_element_by_css_selector(driver, selector, timeout=10),
  • wait_for_text_to_equal(driver, selector, text, timeout=10)
  • import_app(app_file), Load a file with runpy, return the app instance.

More resources

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pytest-dash, version 1.0.1
Filename, size File type Python version Upload date Hashes
Filename, size pytest-dash-1.0.1.tar.gz (4.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page