plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.4k stars 2.06k forks source link

NameError: name 'DashComposite' is not defined #1764

Closed juliausp closed 3 months ago

juliausp commented 3 years ago

Describe your context


Package              Version
-------------------- ---------
amqp                 5.0.6
atomicwrites         1.4.0
attrs                21.2.0
beautifulsoup4       4.10.0
billiard             3.6.4.0
Brotli               1.0.9
celery               5.1.2
certifi              2021.5.30
charset-normalizer   2.0.6
click                7.1.2
click-didyoumean     0.0.3
click-plugins        1.1.1
click-repl           0.2.0
colorama             0.4.4
dash                 2.0.0
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0
dill                 0.3.4
diskcache            5.2.1
flaky                3.7.0
Flask                2.0.1
Flask-Compress       1.10.1
idna                 3.2
iniconfig            1.1.1
itsdangerous         2.0.1
Jinja2               3.0.1
kombu                5.1.0
lxml                 4.6.3
MarkupSafe           2.0.1
multiprocess         0.70.12.2
numpy                1.21.2
packaging            21.0
pandas               1.3.3
percy                2.0.2
pip                  21.2.4
plotly               5.3.1
pluggy               1.0.0
prompt-toolkit       3.0.20
psutil               5.8.0
py                   1.10.0
pyparsing            2.4.7
pytest               6.2.5
pytest-mock          3.6.1
pytest-sugar         0.9.4
python-dateutil      2.8.2
pytz                 2021.1
redis                3.5.3
requests             2.26.0
selenium             3.141.0
setuptools           51.3.3
six                  1.16.0
soupsieve            2.2.1
tenacity             8.0.1
termcolor            1.1.0
toml                 0.10.2
urllib3              1.26.6
vine                 5.0.0
waitress             2.0.0
wcwidth              0.2.5
Werkzeug             2.0.1
wheel                0.36.2

Operating System: Windows 10 Ubuntu 20.04 (WSL)

Describe the bug

I would like to run a test in my gitlab-ci.yml. The test passes locally, but the gitlab-ci pipeline fails, giving the following error message: A minimum example is provided.

============================= test session starts ==============================
platform linux -- Python 3.8.0, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /builds/jwinter/dash_testing_in_gitlab_ci
plugins: dash-2.0.0
collected 1 item
test_app.py E                                                            [100%]
==================================== ERRORS ====================================
________________________ ERROR at setup of test_example ________________________
request = <SubRequest 'dash_duo' for <Function test_example>>
dash_thread_server = <dash.testing.application_runners.ThreadedRunner object at 0x7f12b8d2a130>
tmpdir = local('/tmp/pytest-of-root/pytest-0/test_example0')
    @pytest.fixture
    def dash_duo(request, dash_thread_server, tmpdir):
>       with DashComposite(
            dash_thread_server,
            browser=request.config.getoption("webdriver"),
            remote=request.config.getoption("remote"),
            remote_url=request.config.getoption("remote_url"),
            headless=request.config.getoption("headless"),
            options=request.config.hook.pytest_setup_options(),
            download_path=tmpdir.mkdir("download").strpath,
            percy_assets_root=request.config.getoption("percy_assets"),
            percy_finalize=request.config.getoption("nopercyfinalize"),
            pause=request.config.getoption("pause"),
        ) as dc:
E       NameError: name 'DashComposite' is not defined
/usr/local/lib/python3.8/site-packages/dash/testing/plugin.py:141: NameError
=========================== short test summary info ============================
ERROR test_app.py::test_example - NameError: name 'DashComposite' is not defined
=============================== 1 error in 0.09s ===============================

Project structure:

My File Structure
├── .gitlab-ci.yml
├── app.py
├── conftest.py
├── requirements_for_testing.txt
├── test_app.py

app.py

copy of https://dash.plotly.com/layout

from dash import dcc, html
import dash
import plotly.express as px
import pandas as pd

app = dash.Dash(__name__)

df = pd.DataFrame({
    "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
    "Amount": [4, 1, 2, 2, 4, 5],
    "City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})

fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for your data.
    '''),

    dcc.Graph(
        id='example-graph',
        figure=fig
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

gitlab.ci

So far, I get no difference if I add

def pytest_setup_options(): options = Options() options.add_argument('--headless') return options


 *test_app.py*
```python

from dash.testing.application_runners import import_app
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions

def test_example(dash_duo):
    app = import_app(
        app_file='app')
    dash_duo.start_server(app)
    WebDriverWait(dash_duo.driver, 10).until(
        expected_conditions.visibility_of_element_located(
            (By.CSS_SELECTOR, "#example-graph")))
    assert dash_duo.driver.find_element_by_css_selector(
        "#example-graph").is_displayed()

requirements_for_testing.txt

dash >= 2.0.0
dash[testing]
pytest
selenium
pandas
plotly
requests

Expected behavior

Please help me to write a gitlab-ci.yml file that makes it possible to run the test without this error. Thank you very much for considering this issue. I haven't been able to find anything on this error.

mayankmehtani commented 2 years ago

Were you able to fix this?

ishovkun commented 2 years ago

FYI, I fixed it. The problem in my case was related to a missing library (beautifulsoup4).

As the test script imports various modules within a try-except block, the export failed in my case without any warnings. This caused DashComposite to not be present in the namespace.

Hope this helps.

gvwilson commented 3 months ago

Hi - we are tidying up stale issues and PRs in Plotly's public repositories so that we can focus on things that are most important to our community. If this issue is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. (Please note that we will give priority to reports that include a short reproducible example.) If you'd like to submit a PR, we'd be happy to prioritize a review, and if it's a request for tech support, please post in our community forum. Thank you - @gvwilson