]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: update test to avoid using exception handling as an assertion
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 28 Sep 2023 15:02:37 +0000 (11:02 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 5 Oct 2023 21:05:33 +0000 (17:05 -0400)
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 <jmulligan@redhat.com>
src/cephadm/tests/test_cephadm.py

index ff474c23ccd9de006033d18c367fa23018f8593f..7e31b26307c36a47f039c39e996a7c972d2736ee 100644 (file)
@@ -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')