From 3df1679658dc56409b1e47a99468a65767bfaf62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Beraud?= Date: Tue, 9 Jun 2020 10:43:32 +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. Also enabled the hacking check that should have caught this, it was missing from tox.ini along with most of the other in-tree hacking checks we have added over the years. Change-Id: Id91175d0db8b8edc72f0dd98925ddbf7415bb881 --- HACKING.rst | 2 ++ lower-constraints.txt | 1 - neutron/tests/unit/common/ovn/test_utils.py | 3 ++- tox.ini | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/HACKING.rst b/HACKING.rst index 19b0098170c..da137db0eee 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -26,6 +26,8 @@ Below you can find a list of checks specific to this repository. - [N343] Production code must not import from neutron.tests.* - [N344] Python 3: Do not use filter(lambda obj: test(obj), data). Replace it with [obj for obj in data if test(obj)]. +- [N346] Use neutron_lib.db.api.sqla_listen rather than sqlalchemy +- [N347] Test code must not import mock library .. note:: When adding a new hacking check to this repository or ``neutron-lib``, make diff --git a/lower-constraints.txt b/lower-constraints.txt index b436a88f511..0672190c3f9 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -44,7 +44,6 @@ logilab-common==1.4.1 logutils==0.3.5 Mako==0.4.0 MarkupSafe==1.0 -mock==3.0.0 monotonic==0.6;python_version<'3.3' mox3==0.20.0 msgpack-python==0.4.0 diff --git a/neutron/tests/unit/common/ovn/test_utils.py b/neutron/tests/unit/common/ovn/test_utils.py index e2bcd6cd137..489a388842b 100644 --- a/neutron/tests/unit/common/ovn/test_utils.py +++ b/neutron/tests/unit/common/ovn/test_utils.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.api.definitions import extra_dhcp_opt as edo_ext from neutron.common.ovn import constants diff --git a/tox.ini b/tox.ini index cfe56460b78..0a78657937f 100644 --- a/tox.ini +++ b/tox.ini @@ -172,8 +172,17 @@ import-order-style = pep8 [flake8:local-plugins] extension = # Checks specific to neutron repo + N322 = neutron.hacking.checks:check_assert_called_once_with + N328 = neutron.hacking.checks:check_asserttruefalse + N330 = neutron.hacking.checks:check_assertempty + N331 = neutron.hacking.checks:check_assertisinstance + N332 = neutron.hacking.checks:check_assertequal_for_httpcode N340 = neutron.hacking.checks:check_oslo_i18n_wrapper N341 = neutron.hacking.checks:check_builtins_gettext + N343 = neutron.hacking.checks:check_no_imports_from_tests + N344 = neutron.hacking.checks:check_python3_no_filter + N346 = neutron.hacking.checks:check_no_sqlalchemy_event_import + N347 = neutron.hacking.checks:check_no_import_mock # Checks from neutron-lib N521 = neutron_lib.hacking.checks:use_jsonutils N524 = neutron_lib.hacking.checks:check_no_contextlib_nested