]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: don't fail unit tests if can't import AsyncMock
authorAdam King <adking@redhat.com>
Mon, 30 Aug 2021 20:18:19 +0000 (16:18 -0400)
committerAdam King <adking@redhat.com>
Tue, 31 Aug 2021 16:51:00 +0000 (12:51 -0400)
AsyncMock was added in python 3.8. We don't want unit tests to
be failing if somebody tries running them with pytohn 3.7. Our
Jenkins job should be unaffected and still run the test.

Signed-off-by: Adam King <adking@redhat.com>
src/pybind/mgr/cephadm/tests/test_cephadm.py

index b0026735058f272adc2e25e761ddc44709237e25..93cf942085df66808f1d81e50b7ec1d526724d86 100644 (file)
@@ -1,5 +1,9 @@
 import json
-from unittest.mock import AsyncMock
+try:
+    # AsyncMock was not added until python 3.8
+    from unittest.mock import AsyncMock
+except ImportError:
+    pass
 from contextlib import contextmanager
 
 import pytest
@@ -1083,6 +1087,9 @@ spec:
         check_execute_command.return_value = ''
         execute_command.return_value = '', '', 0
 
+        if not AsyncMock:
+            # can't run this test if we could not import AsyncMock
+            return
         mock_connect = AsyncMock(return_value='')
         with mock.patch("asyncssh.connect", new=mock_connect) as asyncssh_connect:
             with with_host(cephadm_module, 'test'):