Merge "Catch additional invalid mock import statement"

This commit is contained in:
Zuul 2020-05-27 07:50:57 +00:00 committed by Gerrit Code Review
commit d92d317873
2 changed files with 6 additions and 3 deletions

View File

@ -38,6 +38,7 @@ 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")
import_from_mock = re.compile(r"\bfrom[\s]+mock[\s]+import\b")
@core.flake8ext
@ -234,5 +235,6 @@ def check_no_import_mock(logical_line, filename, noqa):
if 'neutron/tests/' not in filename:
return
if re.match(import_mock, logical_line):
yield(0, msg)
for regex in import_mock, import_from_mock:
if re.match(regex, logical_line):
yield(0, msg)

View File

@ -208,7 +208,8 @@ class HackingTestCase(base.BaseTestCase):
def test_check_no_import_mock(self):
pass_line = 'from unittest import mock'
fail_lines = ('import mock',
'import mock as mock_lib')
'import mock as mock_lib',
'from mock import patch')
self.assertEqual(
0, len(list(
checks.check_no_import_mock(