From ffe1f2f8f159749905e224dbaa06f79681063b08 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 28 Sep 2023 11:02:37 -0400 Subject: [PATCH] cephadm: update test to avoid using exception handling as an assertion The use of an exception as an assertion mostly works but has the side effect of hiding other errors. Hiding these errors can make it hard to debug problems in this code path, as it did for me recently. Update the test to use a standard assertion as well as asserting that the assertion must have been called. Signed-off-by: John Mulligan --- src/cephadm/tests/test_cephadm.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index ff474c23ccd9d..7e31b26307c36 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -423,13 +423,12 @@ class TestCephAdm(object): ) def _crush_location_checker(ctx, ident, container, uid, gid, **kwargs): - print(container.args) - raise Exception(' '.join(container.args)) + argval = ' '.join(container.args) + assert '--set-crush-location database=a' in argval _deploy_daemon.side_effect = _crush_location_checker - - with pytest.raises(Exception, match='--set-crush-location database=a'): - _cephadm.command_deploy_from(ctx) + _cephadm.command_deploy_from(ctx) + _deploy_daemon.assert_called() @mock.patch('cephadm.logger') @mock.patch('cephadm.fetch_custom_config_files') -- 2.39.5