hacking: force explicit import of python's mock

Change-Id: I1eccee0ea400487937f59557c69141a66043678b
This commit is contained in:
zhangbailin 2022-12-13 16:25:47 +08:00 committed by Brin Zhang
parent 8164828f7b
commit d477ae1d7b
2 changed files with 7 additions and 3 deletions

View File

@ -204,4 +204,5 @@ def import_stock_mock(logical_line):
N366
"""
if logical_line == 'import mock':
yield 0, msg.get(366)
yield (0, "N366: You must explicitly import python's mock: "
"``from unittest import mock``")

View File

@ -153,8 +153,11 @@ class HackingTestCase(unittest.TestCase):
def test_import_stock_mock(self):
self.assertEqual(1, len(list(checks.import_stock_mock(
'import mock'))))
self.assertEqual(0, len(list(checks.import_stock_mock(
'from unittest import mock'))))
code = """
from unittest import mock
import unittest.mock
"""
self.assertEqual(0, len(list(checks.import_stock_mock(code))))
def test_no_xrange(self):
line = 'xrange(10)'