Skip to content

Commit 5f72204

Browse files
committed
Adds port env var tests
1 parent 1bbe729 commit 5f72204

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

dash/_configs.py

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ def load_dash_env_vars():
3030
"DASH_SILENCE_ROUTES_LOGGING",
3131
"DASH_PRUNE_ERRORS",
3232
"DASH_COMPRESS",
33+
"HOST",
34+
"PORT",
3335
)
3436
}
3537
)

tests/integration/test_integration.py

+8
Original file line numberDiff line numberDiff line change
@@ -974,3 +974,11 @@ def g2(a):
974974
@app.callback(Output("inner-div", "children"), [Input("inner-input", "value")])
975975
def h(a):
976976
return a
977+
978+
979+
def test_inin_024_port_env_success(dash_duo):
980+
app = Dash(__name__)
981+
app.layout = html.Div("hi", "out")
982+
dash_duo.start_server(app, port="12345")
983+
assert dash_duo.server_url == "http://localhost:12345"
984+
dash_duo.wait_for_text_to_equal("#out", "hi")

tests/unit/test_configs.py

+27
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,30 @@ def test_strip_relative_path(prefix, partial_path, expected):
231231
def test_invalid_strip_relative_path(prefix, partial_path):
232232
with pytest.raises(_exc.UnsupportedRelativePath):
233233
strip_relative_path(prefix, partial_path)
234+
235+
236+
def test_port_env_fail_str(empty_environ):
237+
app = Dash()
238+
with pytest.raises(Exception) as excinfo:
239+
app.run_server(port="garbage")
240+
assert (
241+
excinfo.exconly()
242+
== "ValueError: Expecting an integer from 1 to 65535, found port='garbage'"
243+
)
244+
245+
246+
def test_port_env_fail_range(empty_environ):
247+
app = Dash()
248+
with pytest.raises(Exception) as excinfo:
249+
app.run_server(port="0")
250+
assert (
251+
excinfo.exconly()
252+
== "AssertionError: Expecting an integer from 1 to 65535, found port=0"
253+
)
254+
255+
with pytest.raises(Exception) as excinfo:
256+
app.run_server(port="65536")
257+
assert (
258+
excinfo.exconly()
259+
== "AssertionError: Expecting an integer from 1 to 65535, found port=65536"
260+
)

0 commit comments

Comments
 (0)