From: John Mulligan Date: Thu, 28 Sep 2023 15:02:37 +0000 (-0400) Subject: cephadm: update test to avoid using exception handling as an assertion X-Git-Tag: v19.0.0~277^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ffe1f2f8f159749905e224dbaa06f79681063b08;p=ceph.git 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 --- diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index ff474c23ccd..7e31b26307c 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')