Skip to content

Commit 58c8070

Browse files
authored
Testing improvements. (#2036)
* 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
1 parent dc6a57e commit 58c8070

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

Diff for: CHANGELOG.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
1818

1919
- [#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)
2020

21+
- [#2035](https://github.com/plotly/dash/pull/2036) Add type annotations to testing fixtures.
22+
2123
### Fixed
2224

2325
- [#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.
@@ -30,6 +32,10 @@ This project adheres to [Semantic Versioning](https://semver.org/).
3032

3133
- [#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.
3234

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

3541
- [#2016](https://github.com/plotly/dash/pull/2016) Drop the 375px width from default percy_snapshot calls, keep only 1280px
@@ -46,11 +52,6 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4652
- 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.
4753
- Many other mainly JS dependency upgrades to the internals of Dash renderer and components. These may patch bugs or improve performance.
4854

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

5556
## [2.3.1] - 2022-03-29
5657

Diff for: dash/testing/application_runners.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,20 @@ def __init__(self, keep_open=False, stop_timeout=3):
142142
super().__init__(keep_open=keep_open, stop_timeout=stop_timeout)
143143
self.thread = None
144144

145+
def running_and_accessible(self, url):
146+
if self.thread.is_alive():
147+
return self.accessible(url)
148+
raise DashAppLoadingError("Thread is not alive.")
149+
145150
# pylint: disable=arguments-differ
146-
def start(self, app, **kwargs):
151+
def start(self, app, start_timeout=3, **kwargs):
147152
"""Start the app server in threading flavor."""
148153

149154
def _handle_error():
150155
self.stop()
151156

152157
app.server.errorhandler(500)(_handle_error)
153158

154-
if self.thread and self.thread.is_alive():
155-
self.stop()
156-
157159
def run():
158160
app.scripts.config.serve_locally = True
159161
app.css.config.serve_locally = True
@@ -170,16 +172,24 @@ def run():
170172
app.run(threaded=True, **options)
171173
except SystemExit:
172174
logger.info("Server stopped")
175+
except Exception as error:
176+
logger.exception(error)
177+
raise error
173178

174179
retries = 0
175180

176181
while not self.started and retries < 3:
177182
try:
183+
if self.thread and self.thread.is_alive():
184+
self.stop()
185+
178186
self.thread = KillerThread(target=run)
179187
self.thread.daemon = True
180188
self.thread.start()
181189
# wait until server is able to answer http request
182-
wait.until(lambda: self.accessible(self.url), timeout=2)
190+
wait.until(
191+
lambda: self.running_and_accessible(self.url), timeout=start_timeout
192+
)
183193
self.started = self.thread.is_alive()
184194
except Exception as err: # pylint: disable=broad-except
185195
logger.exception(err)

Diff for: dash/testing/plugin.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -95,33 +95,33 @@ def pytest_runtest_makereport(item, call): # pylint: disable=unused-argument
9595

9696

9797
@pytest.fixture
98-
def dash_thread_server():
98+
def dash_thread_server() -> ThreadedRunner:
9999
"""Start a local dash server in a new thread."""
100100
with ThreadedRunner() as starter:
101101
yield starter
102102

103103

104104
@pytest.fixture
105-
def dash_process_server():
105+
def dash_process_server() -> ProcessRunner:
106106
"""Start a Dash server with subprocess.Popen and waitress-serve."""
107107
with ProcessRunner() as starter:
108108
yield starter
109109

110110

111111
@pytest.fixture
112-
def dashr_server():
112+
def dashr_server() -> RRunner:
113113
with RRunner() as starter:
114114
yield starter
115115

116116

117117
@pytest.fixture
118-
def dashjl_server():
118+
def dashjl_server() -> JuliaRunner:
119119
with JuliaRunner() as starter:
120120
yield starter
121121

122122

123123
@pytest.fixture
124-
def dash_br(request, tmpdir):
124+
def dash_br(request, tmpdir) -> Browser:
125125
with Browser(
126126
browser=request.config.getoption("webdriver"),
127127
remote=request.config.getoption("remote"),
@@ -137,7 +137,7 @@ def dash_br(request, tmpdir):
137137

138138

139139
@pytest.fixture
140-
def dash_duo(request, dash_thread_server, tmpdir):
140+
def dash_duo(request, dash_thread_server, tmpdir) -> DashComposite:
141141
with DashComposite(
142142
dash_thread_server,
143143
browser=request.config.getoption("webdriver"),
@@ -154,7 +154,7 @@ def dash_duo(request, dash_thread_server, tmpdir):
154154

155155

156156
@pytest.fixture
157-
def dashr(request, dashr_server, tmpdir):
157+
def dashr(request, dashr_server, tmpdir) -> DashRComposite:
158158
with DashRComposite(
159159
dashr_server,
160160
browser=request.config.getoption("webdriver"),
@@ -171,7 +171,7 @@ def dashr(request, dashr_server, tmpdir):
171171

172172

173173
@pytest.fixture
174-
def dashjl(request, dashjl_server, tmpdir):
174+
def dashjl(request, dashjl_server, tmpdir) -> DashJuliaComposite:
175175
with DashJuliaComposite(
176176
dashjl_server,
177177
browser=request.config.getoption("webdriver"),

0 commit comments

Comments
 (0)