Catch additional invalid mock import statement
As noted in the change to only use unittest.mock, 'from mock import foo' is not treated as invalid, so add it now. Trivialfix Change-Id: I256af9316a2a85f91aeb3c511305d006a51d7246
This commit is contained in:
parent
ba05201e0e
commit
9760f123aa
@ -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)
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user