From 92c0039fd51b4ddfbd3cf64ddce298188d33940a Mon Sep 17 00:00:00 2001 From: Adam King Date: Mon, 30 Aug 2021 16:18:19 -0400 Subject: [PATCH] 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 --- src/pybind/mgr/cephadm/tests/test_cephadm.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index b0026735058f2..93cf942085df6 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'): -- 2.39.5