diff --git a/dash/_configs.py b/dash/_configs.py index f7e8c59bae..802705ed07 100644 --- a/dash/_configs.py +++ b/dash/_configs.py @@ -30,6 +30,8 @@ def load_dash_env_vars(): "DASH_SILENCE_ROUTES_LOGGING", "DASH_PRUNE_ERRORS", "DASH_COMPRESS", + "HOST", + "PORT", ) } ) diff --git a/tests/integration/test_integration.py b/tests/integration/test_integration.py index a81c9bbb56..f1f5c670b2 100644 --- a/tests/integration/test_integration.py +++ b/tests/integration/test_integration.py @@ -974,3 +974,11 @@ def g2(a): @app.callback(Output("inner-div", "children"), [Input("inner-input", "value")]) def h(a): return a + + +def test_inin_024_port_env_success(dash_duo): + app = Dash(__name__) + app.layout = html.Div("hi", "out") + dash_duo.start_server(app, port="12345") + assert dash_duo.server_url == "http://localhost:12345" + dash_duo.wait_for_text_to_equal("#out", "hi") diff --git a/tests/unit/test_configs.py b/tests/unit/test_configs.py index 54ca653a83..2eff1a5660 100644 --- a/tests/unit/test_configs.py +++ b/tests/unit/test_configs.py @@ -231,3 +231,30 @@ def test_strip_relative_path(prefix, partial_path, expected): def test_invalid_strip_relative_path(prefix, partial_path): with pytest.raises(_exc.UnsupportedRelativePath): strip_relative_path(prefix, partial_path) + + +def test_port_env_fail_str(empty_environ): + app = Dash() + with pytest.raises(Exception) as excinfo: + app.run_server(port="garbage") + assert ( + excinfo.exconly() + == "ValueError: Expecting an integer from 1 to 65535, found port='garbage'" + ) + + +def test_port_env_fail_range(empty_environ): + app = Dash() + with pytest.raises(Exception) as excinfo: + app.run_server(port="0") + assert ( + excinfo.exconly() + == "AssertionError: Expecting an integer from 1 to 65535, found port=0" + ) + + with pytest.raises(Exception) as excinfo: + app.run_server(port="65536") + assert ( + excinfo.exconly() + == "AssertionError: Expecting an integer from 1 to 65535, found port=65536" + )