Update hacking.py for @testtools.skip() formatting.
This commit updates the hacking rules to add a strict format for bug
skips. Previously, there was no defined rules for skip formatting
which caused a number of test skips to be added without consistent
formatting. These skips then failed to get picked up by
tools/skip_tracker.py. This commit adds a new hacking test to ensure
that any skips added conform to a format that the skip_tracker will pick
up. HACKING.rst was also updated to explain the new rules being enforced.
Change-Id: I95f3ec7de2ee5e2039d53ad9565b5cec936a7672
diff --git a/HACKING.rst b/HACKING.rst
index a546f8c..eafa81b 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -153,6 +153,19 @@
kwarg2=dict_of_numbers)
+Test Skips
+----------
+If a test is broken because of a bug it is appropriate to skip the test until
+bug has been fixed. However, the skip message should be formatted so that
+Tempest's skip tracking tool can watch the bug status. The skip message should
+contain the string 'Bug' immediately followed by a space. Then the bug number
+should be included in the message '#' in front of the number.
+
+Example::
+
+ @testtools.skip("Skipped until the Bug #980688 is resolved")
+
+
openstack-common
----------------
diff --git a/tools/hacking.py b/tools/hacking.py
index 617682d..528424a 100755
--- a/tools/hacking.py
+++ b/tools/hacking.py
@@ -323,6 +323,30 @@
return (pos, "T404: test functions must "
"not have doc strings")
+SKIP_DECORATOR = '@testtools.skip('
+
+
+def tempest_skip_bugs(physical_line):
+ """Check skip lines for proper bug entries
+
+ T601: Bug not in skip line
+ T602: Bug in message formatted incorrectly
+ """
+
+ pos = physical_line.find(SKIP_DECORATOR)
+
+ skip_re = re.compile(r'^\s*@testtools.skip.*')
+
+ if pos != -1 and skip_re.match(physical_line):
+ bug = re.compile(r'^.*\bbug\b.*', re.IGNORECASE)
+ if bug.match(physical_line) is None:
+ return (pos, 'T601: skips must have an associated bug')
+
+ bug_re = re.compile(r'.*skip\(.*Bug\s\#\d+', re.IGNORECASE)
+
+ if bug_re.match(physical_line) is None:
+ return (pos, 'T602: Bug number formatted incorrectly')
+
FORMAT_RE = re.compile("%(?:"
"%|" # Ignore plain percents