Skip to content

Commit 7c24faa

Browse files
nohalonNoha Alonpre-commit-ci[bot]
authored
Fixes app CLI tests by checking for the dynamically assigned port (#16283)
* Fixes app CLI tests by checking for the dynamically assigned port. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Noha Alon <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4c3ce60 commit 7c24faa

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

tests/tests_app/cli/test_run_app.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from click.testing import CliRunner
99
from tests_app import _PROJECT_ROOT
1010

11+
import lightning_app.core.constants as constants
1112
from lightning_app import LightningApp
1213
from lightning_app.cli.lightning_cli import _run_app, run_app
1314
from lightning_app.runners.runtime_type import RuntimeType
@@ -45,7 +46,11 @@ def _lightning_app_run_and_logging(self, *args, **kwargs):
4546
)
4647
# capture logs.
4748
if open_ui:
48-
lauch_mock.assert_called_with("http://127.0.0.1:7501/view")
49+
50+
# Get the designated port
51+
port = constants.APP_SERVER_PORT
52+
53+
lauch_mock.assert_called_with(f"http://127.0.0.1:{port}/view")
4954
else:
5055
lauch_mock.assert_not_called()
5156
assert result.exit_code == 0
@@ -99,6 +104,10 @@ def test_lightning_run_app_cloud(mock_dispatch: mock.MagicMock, open_ui, caplog,
99104
run_app_comment_commands=False,
100105
enable_basic_auth="",
101106
)
107+
108+
# Get the designated port
109+
port = constants.APP_SERVER_PORT
110+
102111
# capture logs.
103112
# TODO(yurij): refactor the test, check if the actual HTTP request is being sent and that the proper admin
104113
# page is being opened
@@ -115,7 +124,7 @@ def test_lightning_run_app_cloud(mock_dispatch: mock.MagicMock, open_ui, caplog,
115124
cluster_id="",
116125
run_app_comment_commands=False,
117126
enable_basic_auth="",
118-
port=7501,
127+
port=port,
119128
)
120129

121130

@@ -145,6 +154,10 @@ def test_lightning_run_app_cloud_with_run_app_commands(mock_dispatch: mock.Magic
145154
run_app_comment_commands=True,
146155
enable_basic_auth="",
147156
)
157+
158+
# Get the designated port
159+
port = constants.APP_SERVER_PORT
160+
148161
# capture logs.
149162
# TODO(yurij): refactor the test, check if the actual HTTP request is being sent and that the proper admin
150163
# page is being opened
@@ -161,7 +174,7 @@ def test_lightning_run_app_cloud_with_run_app_commands(mock_dispatch: mock.Magic
161174
cluster_id="",
162175
run_app_comment_commands=True,
163176
enable_basic_auth="",
164-
port=7501,
177+
port=port,
165178
)
166179

167180

@@ -211,6 +224,9 @@ def test_lightning_run_app_enable_basic_auth_passed(mock_dispatch: mock.MagicMoc
211224
enable_basic_auth="username:password",
212225
)
213226

227+
# Get the designated port
228+
port = constants.APP_SERVER_PORT
229+
214230
mock_dispatch.assert_called_with(
215231
Path(os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/app_metadata.py")),
216232
RuntimeType.CLOUD,
@@ -224,5 +240,5 @@ def test_lightning_run_app_enable_basic_auth_passed(mock_dispatch: mock.MagicMoc
224240
cluster_id="",
225241
run_app_comment_commands=False,
226242
enable_basic_auth="username:password",
227-
port=7501,
243+
port=port,
228244
)

0 commit comments

Comments
 (0)