From 8126f888945b0f3ac01dca1da0dc46d1f9ec3679 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Mon, 30 Mar 2020 13:49:50 -0400 Subject: [PATCH] Complete removal of dependency on the "mock" package Now that we are python3 only, we should move to using the built in version of mock that supports all of our testing needs and remove the dependency on the "mock" package. This completes removal of all references to "import mock", changing to "from unittest import mock" in fullstack and functional tests. Added a hacking check to enforce it in future patches. Change-Id: Ifcaf1c21bea0ec3c35278e49cecc90a101a82113 --- neutron/hacking/checks.py | 23 +++++++++++++++++-- neutron/tests/base.py | 2 +- neutron/tests/common/agents/l3_agent.py | 2 +- neutron/tests/fullstack/agents/ovs_agent.py | 2 +- .../functional/agent/common/test_ovs_lib.py | 2 +- neutron/tests/functional/agent/l2/base.py | 2 +- .../test_ovs_agent_qos_extension.py | 2 +- .../extensions/qos/test_fip_qos_extension.py | 3 ++- .../test_conntrack_helper_extension.py | 3 +-- .../test_gateway_ip_qos_extension.py | 3 ++- .../test_port_forwarding_extension.py | 2 +- .../tests/functional/agent/l3/framework.py | 2 +- .../functional/agent/l3/test_dvr_router.py | 2 +- .../functional/agent/l3/test_ha_router.py | 2 +- .../agent/l3/test_keepalived_state_change.py | 2 +- .../functional/agent/l3/test_legacy_router.py | 2 +- .../agent/l3/test_namespace_manager.py | 3 ++- .../tests/functional/agent/linux/test_dhcp.py | 3 ++- .../functional/agent/linux/test_l3_tc_lib.py | 3 ++- .../functional/agent/linux/test_tc_lib.py | 2 +- .../agent/ovn/metadata/test_metadata_agent.py | 3 ++- .../tests/functional/agent/test_dhcp_agent.py | 2 +- .../functional/agent/test_l2_lb_agent.py | 3 ++- .../functional/agent/test_l2_ovs_agent.py | 2 +- .../tests/functional/agent/test_ovs_lib.py | 2 +- neutron/tests/functional/base.py | 2 +- .../cmd/test_linuxbridge_cleanup.py | 3 ++- .../functional/cmd/test_netns_cleanup.py | 2 +- neutron/tests/functional/db/test_network.py | 3 ++- .../functional/pecan_wsgi/test_controllers.py | 3 ++- .../functional/pecan_wsgi/test_functional.py | 2 +- .../tests/functional/pecan_wsgi/test_hooks.py | 3 ++- .../mech_driver/ovsdb/extensions/test_qos.py | 3 ++- .../ovn/mech_driver/ovsdb/test_maintenance.py | 3 ++- .../ovsdb/test_ovn_db_resources.py | 3 +-- .../ovn/mech_driver/ovsdb/test_ovn_db_sync.py | 2 +- .../mech_driver/ovsdb/test_ovsdb_monitor.py | 3 ++- .../ovn/mech_driver/test_mech_driver.py | 2 +- .../conntrack_helper/test_conntrack_helper.py | 2 +- .../l3_router/test_l3_dvr_ha_router_plugin.py | 3 ++- .../l3_router/test_l3_dvr_router_plugin.py | 3 ++- .../services/logapi/test_logging.py | 2 +- .../functional/services/ovn_l3/test_plugin.py | 2 +- .../portforwarding/test_port_forwarding.py | 3 ++- .../openvswitch/agent/test_ovsdb_handler.py | 2 +- .../openvswitch/agent/test_trunk_manager.py | 2 +- .../services/trunk/rpc/test_server.py | 2 +- neutron/tests/functional/test_server.py | 2 +- .../tests/common/test_net_helpers.py | 3 +-- neutron/tests/unit/hacking/test_checks.py | 18 +++++++++++++++ test-requirements.txt | 1 - 51 files changed, 104 insertions(+), 54 deletions(-) diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py index 2d221523ab0..eea4d97961e 100644 --- a/neutron/hacking/checks.py +++ b/neutron/hacking/checks.py @@ -47,6 +47,8 @@ tests_imports_dot = re.compile(r"\bimport[\s]+neutron.tests\b") tests_imports_from1 = re.compile(r"\bfrom[\s]+neutron.tests\b") tests_imports_from2 = re.compile(r"\bfrom[\s]+neutron[\s]+import[\s]+tests\b") +import_mock = re.compile(r"\bimport[\s]+mock\b") + @flake8ext def check_assert_called_once_with(logical_line, filename): @@ -202,9 +204,9 @@ def check_builtins_gettext(logical_line, tokens, filename, lines, noqa): @flake8ext def check_no_imports_from_tests(logical_line, filename, noqa): - """N343 Production code must not import from neutron.tests.* + """N343 - Production code must not import from neutron.tests.* """ - msg = ("N343 Production code must not import from neutron.tests.*") + msg = ("N343: Production code must not import from neutron.tests.*") if noqa: return @@ -246,6 +248,22 @@ def check_no_sqlalchemy_event_import(logical_line, filename, noqa): "between unit tests") +@flake8ext +def check_no_import_mock(logical_line, filename, noqa): + """N347 - Test code must not import mock library + """ + msg = ("N347: Test code must not import mock library") + + if noqa: + return + + if 'neutron/tests/' not in filename: + return + + if re.match(import_mock, logical_line): + yield(0, msg) + + def factory(register): checks.factory(register) register(check_assert_called_once_with) @@ -258,3 +276,4 @@ def factory(register): register(check_no_imports_from_tests) register(check_python3_no_filter) register(check_no_sqlalchemy_event_import) + register(check_no_import_mock) diff --git a/neutron/tests/base.py b/neutron/tests/base.py index edc10d1bb4b..d223de5d500 100644 --- a/neutron/tests/base.py +++ b/neutron/tests/base.py @@ -24,10 +24,10 @@ import logging import os import os.path import threading +from unittest import mock import eventlet.timeout import fixtures -import mock from neutron_lib.callbacks import manager as registry_manager from neutron_lib.db import api as db_api from neutron_lib import fixture diff --git a/neutron/tests/common/agents/l3_agent.py b/neutron/tests/common/agents/l3_agent.py index d22060ca75a..3281982cb0f 100755 --- a/neutron/tests/common/agents/l3_agent.py +++ b/neutron/tests/common/agents/l3_agent.py @@ -14,8 +14,8 @@ import sys import types +from unittest import mock -import mock from neutron_lib import constants from oslo_config import cfg diff --git a/neutron/tests/fullstack/agents/ovs_agent.py b/neutron/tests/fullstack/agents/ovs_agent.py index a4c7801f562..926fa911046 100755 --- a/neutron/tests/fullstack/agents/ovs_agent.py +++ b/neutron/tests/fullstack/agents/ovs_agent.py @@ -14,8 +14,8 @@ # under the License. import sys +from unittest import mock -import mock from oslo_config import cfg from neutron.agent.common import ovs_lib diff --git a/neutron/tests/functional/agent/common/test_ovs_lib.py b/neutron/tests/functional/agent/common/test_ovs_lib.py index 02de426e31f..e6cd6bd3714 100644 --- a/neutron/tests/functional/agent/common/test_ovs_lib.py +++ b/neutron/tests/functional/agent/common/test_ovs_lib.py @@ -14,8 +14,8 @@ # under the License. import functools +from unittest import mock -import mock from neutron_lib.services.qos import constants as qos_constants from oslo_utils import uuidutils import six diff --git a/neutron/tests/functional/agent/l2/base.py b/neutron/tests/functional/agent/l2/base.py index 237580a33f2..ef4d6906f6a 100644 --- a/neutron/tests/functional/agent/l2/base.py +++ b/neutron/tests/functional/agent/l2/base.py @@ -15,10 +15,10 @@ # under the License. import random +from unittest import mock import eventlet import fixtures -import mock from neutron_lib import constants as n_const from neutron_lib.utils import net from oslo_config import cfg diff --git a/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py b/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py index 72981c0c85c..2e506b89f45 100644 --- a/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py +++ b/neutron/tests/functional/agent/l2/extensions/test_ovs_agent_qos_extension.py @@ -14,8 +14,8 @@ # under the License. import copy +from unittest import mock -import mock from neutron_lib import constants from oslo_utils import uuidutils import testscenarios diff --git a/neutron/tests/functional/agent/l3/extensions/qos/test_fip_qos_extension.py b/neutron/tests/functional/agent/l3/extensions/qos/test_fip_qos_extension.py index 0a3f695678f..d94b05aa5cf 100644 --- a/neutron/tests/functional/agent/l3/extensions/qos/test_fip_qos_extension.py +++ b/neutron/tests/functional/agent/l3/extensions/qos/test_fip_qos_extension.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants from neutron_lib import exceptions from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/l3/extensions/test_conntrack_helper_extension.py b/neutron/tests/functional/agent/l3/extensions/test_conntrack_helper_extension.py index a96cc3b6fce..6e84f9e239b 100644 --- a/neutron/tests/functional/agent/l3/extensions/test_conntrack_helper_extension.py +++ b/neutron/tests/functional/agent/l3/extensions/test_conntrack_helper_extension.py @@ -15,8 +15,7 @@ import collections - -import mock +from unittest import mock from neutron_lib import constants from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/l3/extensions/test_gateway_ip_qos_extension.py b/neutron/tests/functional/agent/l3/extensions/test_gateway_ip_qos_extension.py index 7c551a93e32..c9df3fe006c 100644 --- a/neutron/tests/functional/agent/l3/extensions/test_gateway_ip_qos_extension.py +++ b/neutron/tests/functional/agent/l3/extensions/test_gateway_ip_qos_extension.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants from neutron_lib import exceptions from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/l3/extensions/test_port_forwarding_extension.py b/neutron/tests/functional/agent/l3/extensions/test_port_forwarding_extension.py index 78d916f2488..9cc216221aa 100644 --- a/neutron/tests/functional/agent/l3/extensions/test_port_forwarding_extension.py +++ b/neutron/tests/functional/agent/l3/extensions/test_port_forwarding_extension.py @@ -15,11 +15,11 @@ import os import re +from unittest import mock from neutron_lib import constants from oslo_utils import uuidutils -import mock from neutron.agent.l3 import agent as neutron_l3_agent from neutron.agent.l3.extensions import port_forwarding as pf from neutron.agent.linux import ip_lib diff --git a/neutron/tests/functional/agent/l3/framework.py b/neutron/tests/functional/agent/l3/framework.py index 25506d25011..00deb8fb020 100644 --- a/neutron/tests/functional/agent/l3/framework.py +++ b/neutron/tests/functional/agent/l3/framework.py @@ -15,8 +15,8 @@ import copy import functools +from unittest import mock -import mock import netaddr from neutron_lib import constants from oslo_config import cfg diff --git a/neutron/tests/functional/agent/l3/test_dvr_router.py b/neutron/tests/functional/agent/l3/test_dvr_router.py index 61b9546e97f..1cb0ec905bf 100644 --- a/neutron/tests/functional/agent/l3/test_dvr_router.py +++ b/neutron/tests/functional/agent/l3/test_dvr_router.py @@ -15,8 +15,8 @@ import copy import functools +from unittest import mock -import mock import netaddr from neutron_lib.api.definitions import portbindings from neutron_lib import constants as lib_constants diff --git a/neutron/tests/functional/agent/l3/test_ha_router.py b/neutron/tests/functional/agent/l3/test_ha_router.py index bb545523357..e547f86b66e 100644 --- a/neutron/tests/functional/agent/l3/test_ha_router.py +++ b/neutron/tests/functional/agent/l3/test_ha_router.py @@ -14,8 +14,8 @@ # under the License. import copy +from unittest import mock -import mock from neutron_lib import constants from oslo_utils import netutils import testtools diff --git a/neutron/tests/functional/agent/l3/test_keepalived_state_change.py b/neutron/tests/functional/agent/l3/test_keepalived_state_change.py index 87d25f26e00..f19c799b51a 100644 --- a/neutron/tests/functional/agent/l3/test_keepalived_state_change.py +++ b/neutron/tests/functional/agent/l3/test_keepalived_state_change.py @@ -14,9 +14,9 @@ import functools import os +from unittest import mock import eventlet -import mock import netaddr from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/l3/test_legacy_router.py b/neutron/tests/functional/agent/l3/test_legacy_router.py index ec86e83753e..e27bbeaee03 100644 --- a/neutron/tests/functional/agent/l3/test_legacy_router.py +++ b/neutron/tests/functional/agent/l3/test_legacy_router.py @@ -14,8 +14,8 @@ # under the License. import copy +from unittest import mock -import mock from neutron_lib.callbacks import events from neutron_lib.callbacks import registry from neutron_lib.callbacks import resources diff --git a/neutron/tests/functional/agent/l3/test_namespace_manager.py b/neutron/tests/functional/agent/l3/test_namespace_manager.py index b68d0fe5288..8c996164400 100644 --- a/neutron/tests/functional/agent/l3/test_namespace_manager.py +++ b/neutron/tests/functional/agent/l3/test_namespace_manager.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_config import cfg from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/linux/test_dhcp.py b/neutron/tests/functional/agent/linux/test_dhcp.py index fc559bdd29c..cdd7c11265e 100644 --- a/neutron/tests/functional/agent/linux/test_dhcp.py +++ b/neutron/tests/functional/agent/linux/test_dhcp.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants from oslo_config import cfg diff --git a/neutron/tests/functional/agent/linux/test_l3_tc_lib.py b/neutron/tests/functional/agent/linux/test_l3_tc_lib.py index fd1142d76a2..2b22d1bd9ff 100644 --- a/neutron/tests/functional/agent/linux/test_l3_tc_lib.py +++ b/neutron/tests/functional/agent/linux/test_l3_tc_lib.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants as common_constants from neutron_lib import exceptions from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/linux/test_tc_lib.py b/neutron/tests/functional/agent/linux/test_tc_lib.py index e4e882cd179..f0211b145c7 100644 --- a/neutron/tests/functional/agent/linux/test_tc_lib.py +++ b/neutron/tests/functional/agent/linux/test_tc_lib.py @@ -14,8 +14,8 @@ # under the License. import random +from unittest import mock -import mock import netaddr from neutron_lib.services.qos import constants as qos_consts from oslo_utils import uuidutils diff --git a/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py b/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py index 04cb9975a4b..311101fb6a2 100644 --- a/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py +++ b/neutron/tests/functional/agent/ovn/metadata/test_metadata_agent.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_config import fixture as fixture_config from oslo_utils import uuidutils from ovsdbapp.backend.ovs_idl import event diff --git a/neutron/tests/functional/agent/test_dhcp_agent.py b/neutron/tests/functional/agent/test_dhcp_agent.py index 88a5797f427..ca1354cbd00 100644 --- a/neutron/tests/functional/agent/test_dhcp_agent.py +++ b/neutron/tests/functional/agent/test_dhcp_agent.py @@ -15,10 +15,10 @@ import copy import os.path +from unittest import mock import eventlet import fixtures -import mock import netaddr from neutron_lib import constants as lib_const from oslo_config import fixture as fixture_config diff --git a/neutron/tests/functional/agent/test_l2_lb_agent.py b/neutron/tests/functional/agent/test_l2_lb_agent.py index 08ffb3662c8..55e658608cd 100644 --- a/neutron/tests/functional/agent/test_l2_lb_agent.py +++ b/neutron/tests/functional/agent/test_l2_lb_agent.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_config import cfg from oslo_utils import uuidutils import testtools diff --git a/neutron/tests/functional/agent/test_l2_ovs_agent.py b/neutron/tests/functional/agent/test_l2_ovs_agent.py index 0aabb585a31..391b622c97f 100644 --- a/neutron/tests/functional/agent/test_l2_ovs_agent.py +++ b/neutron/tests/functional/agent/test_l2_ovs_agent.py @@ -15,8 +15,8 @@ # under the License. import time +from unittest import mock -import mock from neutron_lib.callbacks import events from neutron_lib.callbacks import registry from neutron_lib.callbacks import resources diff --git a/neutron/tests/functional/agent/test_ovs_lib.py b/neutron/tests/functional/agent/test_ovs_lib.py index d85cdce167e..e8fc75e2dcd 100644 --- a/neutron/tests/functional/agent/test_ovs_lib.py +++ b/neutron/tests/functional/agent/test_ovs_lib.py @@ -14,9 +14,9 @@ # under the License. import collections +from unittest import mock import uuid -import mock from neutron_lib import constants as const from oslo_config import cfg from ovsdbapp.backend.ovs_idl import idlutils diff --git a/neutron/tests/functional/base.py b/neutron/tests/functional/base.py index f1731a1a3b2..ac1c2e81b53 100644 --- a/neutron/tests/functional/base.py +++ b/neutron/tests/functional/base.py @@ -17,10 +17,10 @@ from datetime import datetime import errno import os import shutil +from unittest import mock import warnings import fixtures -import mock from neutron_lib import fixture from neutron_lib.plugins import constants from neutron_lib.plugins import directory diff --git a/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py b/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py index 06d195c1d45..c9ebeddd74f 100644 --- a/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py +++ b/neutron/tests/functional/cmd/test_linuxbridge_cleanup.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import fixtures -import mock from neutron_lib import constants from neutron.agent.linux import ip_lib diff --git a/neutron/tests/functional/cmd/test_netns_cleanup.py b/neutron/tests/functional/cmd/test_netns_cleanup.py index 9026e60bb5e..a7019ecd66d 100644 --- a/neutron/tests/functional/cmd/test_netns_cleanup.py +++ b/neutron/tests/functional/cmd/test_netns_cleanup.py @@ -15,9 +15,9 @@ import os import sys +from unittest import mock import eventlet -import mock from neutron_lib import constants as n_const from neutron.agent.l3 import namespaces diff --git a/neutron/tests/functional/db/test_network.py b/neutron/tests/functional/db/test_network.py index 6532d78c503..2160a344bc2 100644 --- a/neutron/tests/functional/db/test_network.py +++ b/neutron/tests/functional/db/test_network.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib import constants from neutron_lib import context diff --git a/neutron/tests/functional/pecan_wsgi/test_controllers.py b/neutron/tests/functional/pecan_wsgi/test_controllers.py index 10bf9532dd4..c77e6c870d8 100644 --- a/neutron/tests/functional/pecan_wsgi/test_controllers.py +++ b/neutron/tests/functional/pecan_wsgi/test_controllers.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants as n_const from neutron_lib import context from neutron_lib.plugins import constants as plugin_constants diff --git a/neutron/tests/functional/pecan_wsgi/test_functional.py b/neutron/tests/functional/pecan_wsgi/test_functional.py index ccd3623b70a..f5b5c7eb331 100644 --- a/neutron/tests/functional/pecan_wsgi/test_functional.py +++ b/neutron/tests/functional/pecan_wsgi/test_functional.py @@ -14,8 +14,8 @@ # under the License. import os +from unittest import mock -import mock from neutron_lib import context from neutron_lib import exceptions as n_exc from neutron_lib.plugins import constants diff --git a/neutron/tests/functional/pecan_wsgi/test_hooks.py b/neutron/tests/functional/pecan_wsgi/test_hooks.py index e1ba0ac6c3e..582b48a1656 100644 --- a/neutron/tests/functional/pecan_wsgi/test_hooks.py +++ b/neutron/tests/functional/pecan_wsgi/test_hooks.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib.api import attributes from neutron_lib.callbacks import events from neutron_lib import context diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/extensions/test_qos.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/extensions/test_qos.py index 2c5961253a9..32a159ca92e 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/extensions/test_qos.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/extensions/test_qos.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib import constants from neutron_lib.services.qos import constants as qos_constants diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py index 3bace092ca6..4b2541ee907 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_maintenance.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_config import cfg from futurist import periodics diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py index be448bf1452..746fd7df09e 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_resources.py @@ -12,8 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. - -import mock +from unittest import mock import netaddr from neutron_lib.api.definitions import dns as dns_apidef diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index d7cd29b6a1f..6a95fc096d1 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron.common.ovn import acl as acl_utils from neutron.common.ovn import constants as ovn_const diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py index 7e7eda060e5..4f1296faaf1 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from oslo_utils import uuidutils from neutron.common.ovn import constants as ovn_const diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index c70a10dd922..210de740e1a 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -13,8 +13,8 @@ # under the License. import functools +from unittest import mock -import mock from neutron_lib.api.definitions import portbindings from oslo_config import cfg from oslo_utils import uuidutils diff --git a/neutron/tests/functional/services/conntrack_helper/test_conntrack_helper.py b/neutron/tests/functional/services/conntrack_helper/test_conntrack_helper.py index 5124d5e925d..e57f0dd15d1 100644 --- a/neutron/tests/functional/services/conntrack_helper/test_conntrack_helper.py +++ b/neutron/tests/functional/services/conntrack_helper/test_conntrack_helper.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron_lib.api.definitions import l3_conntrack_helper as apidef from neutron_lib import exceptions as lib_exc diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py index cb1449072d7..19eedb7610d 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_ha_router_plugin.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib.agent import topics from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import l3 as l3_apidef diff --git a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py index 96d144b910f..e823b98836e 100644 --- a/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py +++ b/neutron/tests/functional/services/l3_router/test_l3_dvr_router_plugin.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib.agent import topics from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import l3 as l3_apidef diff --git a/neutron/tests/functional/services/logapi/test_logging.py b/neutron/tests/functional/services/logapi/test_logging.py index 887620cb96f..0a31b973386 100644 --- a/neutron/tests/functional/services/logapi/test_logging.py +++ b/neutron/tests/functional/services/logapi/test_logging.py @@ -14,8 +14,8 @@ # under the License. import re +from unittest import mock -import mock from neutron_lib import constants from neutron_lib import context as neutron_context from oslo_config import cfg diff --git a/neutron/tests/functional/services/ovn_l3/test_plugin.py b/neutron/tests/functional/services/ovn_l3/test_plugin.py index 780800f97d5..93d07e21b5e 100644 --- a/neutron/tests/functional/services/ovn_l3/test_plugin.py +++ b/neutron/tests/functional/services/ovn_l3/test_plugin.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron.common.ovn import constants as ovn_const from neutron.common.ovn import utils as ovn_utils diff --git a/neutron/tests/functional/services/portforwarding/test_port_forwarding.py b/neutron/tests/functional/services/portforwarding/test_port_forwarding.py index 29a944a86d2..d8b45412451 100644 --- a/neutron/tests/functional/services/portforwarding/test_port_forwarding.py +++ b/neutron/tests/functional/services/portforwarding/test_port_forwarding.py @@ -10,7 +10,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutron_lib.api.definitions import fip_pf_description as ext_apidef from neutron_lib.api.definitions import floating_ip_port_forwarding as apidef from neutron_lib.callbacks import exceptions as c_exc diff --git a/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_ovsdb_handler.py b/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_ovsdb_handler.py index bed29e47ab0..2e5edea593d 100644 --- a/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_ovsdb_handler.py +++ b/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_ovsdb_handler.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron_lib import constants as n_consts from neutron_lib.utils import helpers diff --git a/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_trunk_manager.py b/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_trunk_manager.py index 08db9a7d7f8..3842739644e 100644 --- a/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_trunk_manager.py +++ b/neutron/tests/functional/services/trunk/drivers/openvswitch/agent/test_trunk_manager.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron_lib.utils import net from oslo_log import log as logging diff --git a/neutron/tests/functional/services/trunk/rpc/test_server.py b/neutron/tests/functional/services/trunk/rpc/test_server.py index 0af3afa0365..40ae1cae703 100644 --- a/neutron/tests/functional/services/trunk/rpc/test_server.py +++ b/neutron/tests/functional/services/trunk/rpc/test_server.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from neutron_lib.services.trunk import constants diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index 01377d3b73e..29cc761d552 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -18,9 +18,9 @@ import signal import socket import time import traceback +from unittest import mock import httplib2 -import mock from neutron_lib import worker as neutron_worker from oslo_config import cfg import psutil diff --git a/neutron/tests/functional/tests/common/test_net_helpers.py b/neutron/tests/functional/tests/common/test_net_helpers.py index 0be627cb6ac..e5e4ec44644 100644 --- a/neutron/tests/functional/tests/common/test_net_helpers.py +++ b/neutron/tests/functional/tests/common/test_net_helpers.py @@ -13,8 +13,7 @@ # under the License. import signal - -import mock +from unittest import mock from neutron_lib import exceptions as n_exc diff --git a/neutron/tests/unit/hacking/test_checks.py b/neutron/tests/unit/hacking/test_checks.py index 18e5b4773a1..82943068d5d 100644 --- a/neutron/tests/unit/hacking/test_checks.py +++ b/neutron/tests/unit/hacking/test_checks.py @@ -208,6 +208,24 @@ class HackingTestCase(base.BaseTestCase): self.assertLinePasses(f, "filter(function, range(0,10))") self.assertLinePasses(f, "lambda x, y: x+y") + def test_check_no_import_mock(self): + pass_line = 'from unittest import mock' + fail_lines = ('import mock', + 'import mock as mock_lib') + self.assertEqual( + 0, len(list( + checks.check_no_import_mock( + pass_line, "neutron/tests/test_fake.py", None)))) + for fail_line in fail_lines: + self.assertEqual( + 0, len(list( + checks.check_no_import_mock( + fail_line, "neutron/common/utils.py", None)))) + self.assertEqual( + 1, len(list( + checks.check_no_import_mock( + fail_line, "neutron/tests/test_fake.py", None)))) + # The following is borrowed from hacking/tests/test_doctest.py. # Tests defined in docstring is easier to understand diff --git a/test-requirements.txt b/test-requirements.txt index 43d563a78f1..b3101e6ebfa 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -7,7 +7,6 @@ coverage!=4.4,>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD flake8-import-order==0.12 # LGPLv3 pycodestyle>=2.0.0 # MIT -mock>=3.0.0 # BSD python-subunit>=1.0.0 # Apache-2.0/BSD testtools>=2.2.0 # MIT testresources>=2.0.0 # Apache-2.0/BSD