From 71bc3193262cdaca59f4a8dfda92d3de76aef47e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Mon, 8 Jun 2020 23:04:01 +0200 Subject: [PATCH] Use unittest.mock instead of mock The mock third party library was needed for mock support in py2 runtimes. Since we now only support py36 and later, we can use the standard lib unittest.mock module instead. Note that https://github.com/openstack/charms.openstack is used during tests and he need `mock`, unfortunatelly it doesn't declare `mock` in its requirements so it retrieve mock from other charm project (cross dependency). So we depend on charms.openstack first and when Ib1ed5b598a52375e29e247db9ab4786df5b6d142 will be merged then CI will pass without errors. Depends-On: Ib1ed5b598a52375e29e247db9ab4786df5b6d142 Change-Id: Id925078c5c04c2f89a570bdf7171c666839f9e40 --- .zuul.yaml | 1 - test-requirements.txt | 5 ----- unit_tests/__init__.py | 2 +- unit_tests/test_actions.py | 2 +- unit_tests/test_actions_openstack_upgrade.py | 2 +- unit_tests/test_nova_cc_contexts.py | 2 +- unit_tests/test_nova_cc_hooks.py | 2 +- unit_tests/test_nova_cc_utils.py | 3 +-- unit_tests/test_utils.py | 2 +- 9 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.zuul.yaml b/.zuul.yaml index b3037e94..0eed1965 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,5 +1,4 @@ - project: templates: - - python35-charm-jobs - openstack-python3-ussuri-jobs - openstack-cover-jobs diff --git a/test-requirements.txt b/test-requirements.txt index f853625d..0aabe171 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -13,11 +13,6 @@ setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb requests>=2.18.4 -# Newer mock seems to have some syntax which is newer than python3.5 (e.g. -# f'{something}' -mock>=1.2,<4.0.0; python_version < '3.6' -mock>=1.2; python_version >= '3.6' - stestr>=2.2.0 # Dependency of stestr. Workaround for diff --git a/unit_tests/__init__.py b/unit_tests/__init__.py index ff55e909..82861fe1 100644 --- a/unit_tests/__init__.py +++ b/unit_tests/__init__.py @@ -14,7 +14,7 @@ import os import sys -import mock +from unittest import mock # python-apt is not installed as part of test-requirements but is imported by # some charmhelpers modules so create a fake import. diff --git a/unit_tests/test_actions.py b/unit_tests/test_actions.py index 1075eb56..1e19f036 100644 --- a/unit_tests/test_actions.py +++ b/unit_tests/test_actions.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import mock +from unittest import mock from unit_tests.test_utils import ( CharmTestCase, diff --git a/unit_tests/test_actions_openstack_upgrade.py b/unit_tests/test_actions_openstack_upgrade.py index 5a10a86f..c6578613 100644 --- a/unit_tests/test_actions_openstack_upgrade.py +++ b/unit_tests/test_actions_openstack_upgrade.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mock import patch +from unittest.mock import patch from unit_tests.test_utils import CharmTestCase import charmhelpers.core.unitdata diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index ea9f6afa..012b63ee 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -13,7 +13,7 @@ # limitations under the License. import json -import mock +from unittest import mock import hooks.nova_cc_context as context diff --git a/unit_tests/test_nova_cc_hooks.py b/unit_tests/test_nova_cc_hooks.py index 2f384c8b..6d0bfa93 100644 --- a/unit_tests/test_nova_cc_hooks.py +++ b/unit_tests/test_nova_cc_hooks.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mock import MagicMock, patch, call +from unittest.mock import MagicMock, patch, call import os import tempfile diff --git a/unit_tests/test_nova_cc_utils.py b/unit_tests/test_nova_cc_utils.py index abc106e7..897c6669 100644 --- a/unit_tests/test_nova_cc_utils.py +++ b/unit_tests/test_nova_cc_utils.py @@ -13,10 +13,9 @@ # limitations under the License. from collections import OrderedDict -from mock import patch, MagicMock, call import subprocess - import charmhelpers.core.unitdata +from unittest.mock import patch, MagicMock, call from unit_tests.test_utils import ( CharmTestCase, diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index 2649f841..6ae7538f 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -21,7 +21,7 @@ import unittest import yaml from contextlib import contextmanager -from mock import patch, MagicMock +from unittest.mock import patch, MagicMock def load_config():