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: Ib658c7f61fe4aceafc1919e366d24ce81ec1dd63
This commit is contained in:
Hervé Beraud 2020-06-08 22:32:14 +02:00 committed by James Page
parent 313e71bc7b
commit 4cbac58ba1
14 changed files with 17 additions and 20 deletions

View File

@ -1,4 +1,4 @@
- project: - project:
templates: templates:
- openstack-python3-charm-jobs - openstack-python3-ussuri-jobs
- openstack-cover-jobs - openstack-cover-jobs

View File

@ -13,11 +13,7 @@ setuptools<50.0.0 # https://github.com/pypa/setuptools/commit/04e3df22df840c6bb
requests>=2.18.4 requests>=2.18.4
# Newer mock seems to have some syntax which is newer than python3.5 (e.g. flake8>=2.2.4,<=2.4.1
# f'{something}'
mock>=1.2,<4.0.0; python_version < '3.6'
mock>=1.2; python_version >= '3.6'
stestr>=2.2.0 stestr>=2.2.0
# Dependency of stestr. Workaround for # Dependency of stestr. Workaround for

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock from unittest import mock
from actions import add_disk from actions import add_disk

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock from unittest import mock
from charmhelpers.core import hookenv from charmhelpers.core import hookenv

View File

@ -11,11 +11,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock
import subprocess
import subprocess
import sys import sys
from unittest import mock
from test_utils import CharmTestCase from test_utils import CharmTestCase
sys.path.append('hooks') sys.path.append('hooks')

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock import unittest.mock as mock
from contextlib import contextmanager from contextlib import contextmanager
from actions import service from actions import service

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock from unittest import mock
from actions import zap_disk from actions import zap_disk

View File

@ -17,7 +17,7 @@ from collections import OrderedDict
import copy import copy
import unittest import unittest
from mock import patch, MagicMock, call from unittest.mock import patch, MagicMock, call
import charmhelpers.contrib.storage.linux.ceph as ceph import charmhelpers.contrib.storage.linux.ceph as ceph

View File

@ -15,7 +15,7 @@
import unittest import unittest
from mock import patch from unittest.mock import patch
with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec: with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f: mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:

View File

@ -18,7 +18,7 @@ import tempfile
import sys import sys
import test_utils import test_utils
from mock import patch, MagicMock from unittest.mock import patch, MagicMock
# python-apt is not installed as part of test-requirements but is imported by # python-apt is not installed as part of test-requirements but is imported by
# some charmhelpers modules so create a fake import. # some charmhelpers modules so create a fake import.

View File

@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import mock from unittest import mock
import test_utils import test_utils
from mock import MagicMock, patch from unittest.mock import MagicMock, patch
with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec: with patch('charmhelpers.contrib.hardening.harden.harden') as mock_dec:
mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f: mock_dec.side_effect = (lambda *dargs, **dkwargs: lambda f:

View File

@ -1,5 +1,5 @@
__author__ = 'Chris Holcombe <chris.holcombe@canonical.com>' __author__ = 'Chris Holcombe <chris.holcombe@canonical.com>'
from mock import patch, call from unittest.mock import patch, call
import test_utils import test_utils
import charms_ceph.utils as ceph import charms_ceph.utils as ceph

View File

@ -1,4 +1,4 @@
from mock import call, patch from unittest.mock import call, patch
from test_utils import CharmTestCase from test_utils import CharmTestCase
from ceph_hooks import check_for_upgrade, notify_mon_of_upgrade from ceph_hooks import check_for_upgrade, notify_mon_of_upgrade

View File

@ -19,7 +19,7 @@ import sys
import yaml import yaml
from contextlib import contextmanager from contextlib import contextmanager
from mock import patch, MagicMock from unittest.mock import patch, MagicMock
# python-apt is not installed as part of test-requirements but is imported by # python-apt is not installed as part of test-requirements but is imported by
# some charmhelpers modules so create a fake import. # some charmhelpers modules so create a fake import.