From beccbb17e2be3272d6acf86f06b5da4da3afd694 Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Wed, 21 Apr 2021 22:23:11 +0000 Subject: [PATCH] Gate-Fix: Replace Octavia hacking O349 with H216 The new flake8 includes check H216 to encourage the use of unittest.mock instead of third party mock modules. Octavia had a hacking check, O349, for the same purpose. Unfortunately, H216 is flagging that check as an improper use. This patch removes O349, in favor of H216, for the Octaiva hacking checks. Change-Id: I5c11c892ca1184624d6d8e111f69ec30cab2a0d8 --- octavia/hacking/checks.py | 17 ----------------- tox.ini | 1 - 2 files changed, 18 deletions(-) diff --git a/octavia/hacking/checks.py b/octavia/hacking/checks.py index eec747609b..52070bb719 100644 --- a/octavia/hacking/checks.py +++ b/octavia/hacking/checks.py @@ -66,8 +66,6 @@ untranslated_exception_re = re.compile(r"raise (?:\w*)\((.*)\)") no_eventlet_re = re.compile(r'(import|from)\s+[(]?eventlet') no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') no_logging_re = re.compile(r'(import|from)\s+[(]?logging') -import_mock_re = re.compile(r"\bimport[\s]+mock\b") -import_from_mock_re = re.compile(r"\bfrom[\s]+mock[\s]+import\b") def _translation_checks_not_enforced(filename): @@ -260,18 +258,3 @@ def check_no_logging_imports(logical_line): if no_logging_re.match(logical_line): msg = 'O348 Usage of Python logging module not allowed, use oslo_log' yield logical_line.index('logging'), msg - - -@core.flake8ext -def check_no_import_mock(logical_line): - """O349 - Test code must not import mock library. - - :param logical_line: The logical line to check. - :returns: None if the logical line passes the check, otherwise a tuple - is yielded that contains the offending index in logical line - and a message describe the check validation failure. - """ - if (import_mock_re.match(logical_line) or - import_from_mock_re.match(logical_line)): - msg = 'O349 Test code must not import mock library, use unittest.mock' - yield 0, msg diff --git a/tox.ini b/tox.ini index cce280918a..e01b2b0400 100644 --- a/tox.ini +++ b/tox.ini @@ -191,7 +191,6 @@ extension = O346 = checks:check_line_continuation_no_backslash O347 = checks:revert_must_have_kwargs O348 = checks:check_no_logging_imports - O349 = checks:check_no_import_mock paths = ./octavia/hacking