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.

import dash

import dash_html_components as html

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

def test_app(start_dash, selenium):
    app = dash.Dash(__name__)
    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
        return 'Clicked: {}'.format(n_clicks)
    btn = selenium.find_element_by_id('click-me')
    out = selenium.find_element_by_id('out')
    assert out.text == 'Clicked: 1'


Load a file with runpy, return the app instance.

def test_app(dash_from_file):
    app = dash_from_file('')


Combine start_dash and dash_from_file.

def test_app(dash_app, selenium):
    app = dash_app('')
    # App has already been started, safe to use selenium from there.
    out = selenium.find_element_by('out')

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 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size pytest-dash-0.1.2.tar.gz (3.0 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