Skip to content

Commit e9542ad

Browse files
Improve Console Output to Indicate Hook Usage in Kedro-Viz (#2235)
Resolves #2145
1 parent a9f8fc7 commit e9542ad

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

package/kedro_viz/launchers/cli/run.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
is_flag=True,
8585
help="An experimental flag to open Kedro-Viz without Kedro project dependencies",
8686
)
87-
def run(
87+
def run( # noqa: PLR0915
8888
host,
8989
port,
9090
browser,
@@ -155,6 +155,16 @@ def run(
155155
port = _find_available_port(host, port)
156156

157157
try:
158+
if include_hooks:
159+
hooks_message = "INFO: Running Kedro-Viz with hooks."
160+
else:
161+
hooks_message = (
162+
"INFO: Running Kedro-Viz without hooks. "
163+
"Try `kedro viz run --include-hooks` to include hook functionality."
164+
)
165+
166+
display_cli_message(hooks_message, "yellow")
167+
158168
if port in _VIZ_PROCESSES and _VIZ_PROCESSES[port].is_alive():
159169
_VIZ_PROCESSES[port].terminate()
160170

package/tests/test_launchers/test_cli/test_run.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def mock_click_echo(mocker):
3232

3333
@pytest.fixture
3434
def mock_project_path(mocker):
35-
mock_path = "/tmp/project_path"
35+
mock_path = Path("/tmp/project_path")
3636
mocker.patch("pathlib.Path.cwd", return_value=mock_path)
3737
return mock_path
3838

@@ -259,6 +259,45 @@ def test_kedro_viz_command_should_log_project_not_found(
259259

260260
mock_click_echo.assert_has_calls(mock_click_echo_calls)
261261

262+
def test_kedro_viz_command_logs_hooks_message(
263+
self, mocker, mock_project_path, mock_click_echo
264+
):
265+
"""
266+
Test that Kedro-Viz logs the correct message when
267+
the `--include-hooks` flag is used or omitted.
268+
"""
269+
# Mock server setup and readiness checks
270+
mocker.patch("kedro_viz.server.run_server")
271+
mocker.patch(
272+
"kedro_viz.launchers.utils._wait_for.__defaults__", (True, 1, True, 1)
273+
)
274+
mocker.patch(
275+
"kedro_viz.launchers.utils._find_kedro_project",
276+
return_value=mock_project_path,
277+
)
278+
279+
runner = CliRunner()
280+
281+
# Test with --include-hooks
282+
with runner.isolated_filesystem():
283+
runner.invoke(main.viz_cli, ["viz", "run", "--include-hooks"])
284+
285+
assert any(
286+
"INFO: Running Kedro-Viz with hooks." in call.args[0]
287+
for call in mock_click_echo.mock_calls
288+
), "Expected message about running with hooks not found."
289+
290+
# Test without --include-hooks
291+
with runner.isolated_filesystem():
292+
runner.invoke(main.viz_cli, ["viz", "run"])
293+
294+
assert any(
295+
"INFO: Running Kedro-Viz without hooks. "
296+
"Try `kedro viz run --include-hooks` to include hook functionality."
297+
in call.args[0]
298+
for call in mock_click_echo.mock_calls
299+
), "Expected message about running without hooks not found."
300+
262301
def test_kedro_viz_command_should_log_outdated_version(
263302
self, mocker, mock_http_response, mock_click_echo, mock_project_path
264303
):

0 commit comments

Comments
 (0)