Skip to main content

pytest fixtures to run dash app.

Project description

pytest-dash

Pytest fixtures for dash

Install

$ pip install pytest-dash

Fixtures

start_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)
    
    start_dash(app)
    
    btn = selenium.find_element_by_id('click-me')
    btn.click()
    
    out = selenium.find_element_by_id('out')
    assert out.text == 'Clicked: 1'

dash_from_file

Load a file with runpy, return the app instance.

def test_app(dash_from_file):
    app = dash_from_file('usage.py')
    ...

dash_app

Combine start_dash and dash_from_file.

def test_app(dash_app, selenium):
    app = dash_app('usage.py')
    # 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.2.0rc2
Filename, size File type Python version Upload date Hashes
Filename, size pytest-dash-0.2.0rc2.tar.gz (3.9 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