Add hacking check for 3rd party mock
Change-Id: I25715d04791e9c8c681a63954719d48f7b390dcd Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
parent
c3c7a6328e
commit
eb915e2dbb
@ -372,3 +372,18 @@ def validate_assertTrue(logical_line, filename):
|
||||
msg = ("C313: Unit tests should use assertTrue(value) instead"
|
||||
" of using assertEqual(True, value).")
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
third_party_mock = re.compile("^import.mock")
|
||||
from_third_party_mock = re.compile("^from.mock.import")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_third_party_mock(logical_line):
|
||||
# We should only use unittest.mock, not the third party mock library that
|
||||
# was needed for py2 support.
|
||||
if (re.match(third_party_mock, logical_line) or
|
||||
re.match(from_third_party_mock, logical_line)):
|
||||
msg = ('C337: Unit tests should use the standard library "mock" '
|
||||
'module, not the third party mock lib.')
|
||||
yield(0, msg)
|
||||
|
@ -293,3 +293,13 @@ class HackingTestCase(test.TestCase):
|
||||
def test_no_test_log(self, first, second, third, fourth):
|
||||
self.assertEqual(first, len(list(checks.no_test_log(
|
||||
"%s('arg')" % second, third, fourth))))
|
||||
|
||||
@ddt.unpack
|
||||
@ddt.data(
|
||||
(1, 'import mock'),
|
||||
(0, 'from unittest import mock'),
|
||||
(1, 'from mock import patch'),
|
||||
(0, 'from unittest.mock import patch'))
|
||||
def test_no_third_party_mock(self, err_count, line):
|
||||
self.assertEqual(err_count, len(list(checks.no_third_party_mock(
|
||||
line))))
|
||||
|
@ -14,8 +14,8 @@
|
||||
|
||||
import errno
|
||||
import re
|
||||
from unittest import mock
|
||||
|
||||
import mock
|
||||
from oslo_utils import units
|
||||
from six.moves import http_client
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user