From: Adam King Date: Mon, 30 Aug 2021 20:18:19 +0000 (-0400) Subject: mgr/cephadm: don't fail unit tests if can't import AsyncMock X-Git-Tag: v17.1.0~970^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=92c0039fd51b4ddfbd3cf64ddce298188d33940a;p=ceph.git mgr/cephadm: don't fail unit tests if can't import AsyncMock 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 --- diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index b0026735058f..93cf942085df 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -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'):