Skip to content

Commit 40b9bbb

Browse files
authored
fix: Fix error handling test so that it tests correct behaviour (#939)
The test appeared to be checking the error status under various error conditions but those conditions were never being reached due to other values causing errors before they were raised. If the intended error was raised, the exit status was also not the one expected.
1 parent dc1c5ef commit 40b9bbb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

tests/unit_tests/test_cli.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,22 @@ def test_env_reload_server_side_error(runner: CliRunner):
406406

407407

408408
@pytest.mark.parametrize(
409-
"exception, expected_exit_code",
409+
"exception, error_message",
410410
[
411-
(ValidationError.from_exception_data(title="Base model", line_errors=[]), 1),
412-
(BlueskyRemoteControlError("Server error"), 1),
413-
(ValueError("Error parsing parameters"), 1),
411+
(
412+
ValidationError.from_exception_data(title="Base model", line_errors=[]),
413+
"('failed to validate the task parameters, ,"
414+
+ " error: 0 validation errors for '\n 'Base model\\n')\n",
415+
),
416+
(
417+
BlueskyRemoteControlError("Server error"),
418+
"'server error with this message: Server error'\n",
419+
),
420+
(ValueError("Error parsing parameters"), "'task could not run'\n"),
414421
],
422+
ids=["validation_error", "remote_control", "value_error"],
415423
)
416-
def test_error_handling(exception, expected_exit_code, runner: CliRunner):
424+
def test_error_handling(exception, error_message, runner: CliRunner):
417425
# Patching the create_task method to raise different exceptions
418426
with patch(
419427
"blueapi.client.rest.BlueapiRestClient.create_task", side_effect=exception
@@ -422,15 +430,15 @@ def test_error_handling(exception, expected_exit_code, runner: CliRunner):
422430
main,
423431
[
424432
"-c",
425-
"tests/example_yaml/valid_stomp_config.yaml",
433+
"tests/unit_tests/example_yaml/valid_stomp_config.yaml",
426434
"controller",
427435
"run",
428436
"sleep",
429-
"'{\"time\": 5}'",
437+
'{"time": 5}',
430438
],
431-
input="\n",
432439
)
433-
assert result.exit_code == expected_exit_code
440+
# error message is printed to stderr but test runner combines output
441+
assert result.stdout == error_message
434442

435443

436444
def test_device_output_formatting():

0 commit comments

Comments
 (0)