Skip to content

Commit

Permalink
Testing improvements. (#2036)
Browse files Browse the repository at this point in the history
* Add start_timeout to threaded test server, set to 3 seconds, log thread exceptions.

* noise

* noise

* noise

* Add type annotations to dash testing fixtures.

* Update changelog.

* noise
  • Loading branch information
T4rk1n authored May 4, 2022
1 parent dc6a57e commit 58c8070
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#2034](https://github.com/plotly/dash/pull/2034) Add `link_target` prop to dcc.Markdown component. Closes [#1827](https://github.com/plotly/dash/issues/1827)

- [#2035](https://github.com/plotly/dash/pull/2036) Add type annotations to testing fixtures.

### Fixed

- [#2029](https://github.com/plotly/dash/pull/2029) Restrict the number of props listed explicitly in generated component constructors - default is 250. This prevents exceeding the Python 3.6 limit of 255 arguments. The omitted props are still in the docstring and can still be provided the same as before, they just won't appear in the signature so autocompletion may be affected.
Expand All @@ -30,6 +32,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).

- [#2035](https://github.com/plotly/dash/pull/2035) Fix [#2033](https://github.com/plotly/dash/issues/2033) In-App error reporting does not render HTML.

- [#1970](https://github.com/plotly/dash/pull/1970) dcc.Dropdown Refactor fixes:
- Fix bug [#1868](https://github.com/plotly/dash/issues/1868) value does not update when selected option removed from options.
- Fix bug [#1908](https://github.com/plotly/dash/issues/1908) Selected options not showing when the value contains a comma.

### Changed

- [#2016](https://github.com/plotly/dash/pull/2016) Drop the 375px width from default percy_snapshot calls, keep only 1280px
Expand All @@ -46,11 +52,6 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Upgrade `black` to v22.3.0 for Python 3.7+ - if you use `dash[ci]` and you call `black`, this may alter your code formatting slightly, including more consistently breaking Python 2 compatibility.
- Many other mainly JS dependency upgrades to the internals of Dash renderer and components. These may patch bugs or improve performance.

### Fixed

- [#1970](https://github.com/plotly/dash/pull/1970) dcc.Dropdown Refactor fixes:
- Fix bug [#1868](https://github.com/plotly/dash/issues/1868) value does not update when selected option removed from options.
- Fix bug [#1908](https://github.com/plotly/dash/issues/1908) Selected options not showing when the value contains a comma.

## [2.3.1] - 2022-03-29

Expand Down
20 changes: 15 additions & 5 deletions dash/testing/application_runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,20 @@ def __init__(self, keep_open=False, stop_timeout=3):
super().__init__(keep_open=keep_open, stop_timeout=stop_timeout)
self.thread = None

def running_and_accessible(self, url):
if self.thread.is_alive():
return self.accessible(url)
raise DashAppLoadingError("Thread is not alive.")

# pylint: disable=arguments-differ
def start(self, app, **kwargs):
def start(self, app, start_timeout=3, **kwargs):
"""Start the app server in threading flavor."""

def _handle_error():
self.stop()

app.server.errorhandler(500)(_handle_error)

if self.thread and self.thread.is_alive():
self.stop()

def run():
app.scripts.config.serve_locally = True
app.css.config.serve_locally = True
Expand All @@ -170,16 +172,24 @@ def run():
app.run(threaded=True, **options)
except SystemExit:
logger.info("Server stopped")
except Exception as error:
logger.exception(error)
raise error

retries = 0

while not self.started and retries < 3:
try:
if self.thread and self.thread.is_alive():
self.stop()

self.thread = KillerThread(target=run)
self.thread.daemon = True
self.thread.start()
# wait until server is able to answer http request
wait.until(lambda: self.accessible(self.url), timeout=2)
wait.until(
lambda: self.running_and_accessible(self.url), timeout=start_timeout
)
self.started = self.thread.is_alive()
except Exception as err: # pylint: disable=broad-except
logger.exception(err)
Expand Down
16 changes: 8 additions & 8 deletions dash/testing/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,33 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument


@pytest.fixture
def dash_thread_server():
def dash_thread_server() -> ThreadedRunner:
"""Start a local dash server in a new thread."""
with ThreadedRunner() as starter:
yield starter


@pytest.fixture
def dash_process_server():
def dash_process_server() -> ProcessRunner:
"""Start a Dash server with subprocess.Popen and waitress-serve."""
with ProcessRunner() as starter:
yield starter


@pytest.fixture
def dashr_server():
def dashr_server() -> RRunner:
with RRunner() as starter:
yield starter


@pytest.fixture
def dashjl_server():
def dashjl_server() -> JuliaRunner:
with JuliaRunner() as starter:
yield starter


@pytest.fixture
def dash_br(request, tmpdir):
def dash_br(request, tmpdir) -> Browser:
with Browser(
browser=request.config.getoption("webdriver"),
remote=request.config.getoption("remote"),
Expand All @@ -137,7 +137,7 @@ def dash_br(request, tmpdir):


@pytest.fixture
def dash_duo(request, dash_thread_server, tmpdir):
def dash_duo(request, dash_thread_server, tmpdir) -> DashComposite:
with DashComposite(
dash_thread_server,
browser=request.config.getoption("webdriver"),
Expand All @@ -154,7 +154,7 @@ def dash_duo(request, dash_thread_server, tmpdir):


@pytest.fixture
def dashr(request, dashr_server, tmpdir):
def dashr(request, dashr_server, tmpdir) -> DashRComposite:
with DashRComposite(
dashr_server,
browser=request.config.getoption("webdriver"),
Expand All @@ -171,7 +171,7 @@ def dashr(request, dashr_server, tmpdir):


@pytest.fixture
def dashjl(request, dashjl_server, tmpdir):
def dashjl(request, dashjl_server, tmpdir) -> DashJuliaComposite:
with DashJuliaComposite(
dashjl_server,
browser=request.config.getoption("webdriver"),
Expand Down

0 comments on commit 58c8070

Please sign in to comment.