From d477ae1d7bc79118e09f3e64b71868dbdab13eb9 Mon Sep 17 00:00:00 2001 From: zhangbailin Date: Tue, 13 Dec 2022 16:25:47 +0800 Subject: [PATCH] hacking: force explicit import of python's mock Change-Id: I1eccee0ea400487937f59557c69141a66043678b --- venus/hacking/checks.py | 3 ++- venus/tests/test_hacking.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/venus/hacking/checks.py b/venus/hacking/checks.py index 344c60c..c3cf900 100644 --- a/venus/hacking/checks.py +++ b/venus/hacking/checks.py @@ -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``") diff --git a/venus/tests/test_hacking.py b/venus/tests/test_hacking.py index c101929..0a4dc21 100644 --- a/venus/tests/test_hacking.py +++ b/venus/tests/test_hacking.py @@ -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)'