From c36782a96a96ecfc35f8af750c29741c769ed515 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Wed, 19 Feb 2020 18:07:23 -0600 Subject: hacking: force explicit import of python's mock Since we dropped support for python 2 [1], we no longer need to use the mock library, which existed to backport py3 functionality into py2. Change Ib44b5bff657c8e76c4f701e14d51a4efda3f6d32 cut over to importing the stock mock, which must be done by saying:: from unittest import mock ...because if you say:: import mock ...you will be using the third party mock library instead, which may or may not be installed. This commit adds hacking check N371 to enforce the former. [1] https://review.opendev.org/#/c/687954/ Change-Id: I71439580e80d33cff62aba807df2b35164a47cbe --- nova/tests/unit/test_hacking.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'nova/tests/unit/test_hacking.py') diff --git a/nova/tests/unit/test_hacking.py b/nova/tests/unit/test_hacking.py index 0cf83abacb..10b2a79db4 100644 --- a/nova/tests/unit/test_hacking.py +++ b/nova/tests/unit/test_hacking.py @@ -1030,3 +1030,16 @@ class HackingTestCase(test.NoDBTestCase): """ errors = [(x + 1, 0, 'N370') for x in range(4)] self._assert_has_errors(code, checks.check_six, expected_errors=errors) + + def test_import_stock_mock(self): + self._assert_has_errors( + "import mock", + checks.import_stock_mock, expected_errors=[(1, 0, 'N371')]) + self._assert_has_errors( + "from mock import patch", + checks.import_stock_mock, expected_errors=[(1, 0, 'N371')]) + code = """ + from unittest import mock + import unittest.mock + """ + self._assert_has_no_errors(code, checks.import_stock_mock) -- cgit v1.2.1