Add hacking check for service tags in scenario
This commit adds a hacking check to ensure that all the tests in the
tempest.scenario directory include a @services decorator.
Part of bp add-service-tags
Change-Id: Ie2f3c384aac568ab791f4d7665d29ea9b3fda7f8
diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py
index 8cfd548..aa97211 100644
--- a/tempest/hacking/checks.py
+++ b/tempest/hacking/checks.py
@@ -22,6 +22,8 @@
SKIP_DECORATOR_RE = re.compile(r'\s*@testtools.skip\((.*)\)')
SKIP_STR_RE = re.compile(r'.*Bug #\d+.*')
PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
+TEST_DEFINITION = re.compile(r'^\s*def test.*')
+SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(')
def skip_bugs(physical_line):
@@ -53,6 +55,21 @@
" in tempest/api/* tests"))
+def scenario_tests_need_service_tags(physical_line, filename,
+ previous_logical):
+ """Check that scenario tests have service tags
+
+ T104: Scenario tests require a services decorator
+ """
+
+ if 'tempest/scenario' in filename:
+ if TEST_DEFINITION.match(physical_line):
+ if not SCENARIO_DECORATOR.match(previous_logical):
+ return (physical_line.find('def'),
+ "T104: Scenario tests require a service decorator")
+
+
def factory(register):
register(skip_bugs)
register(import_no_clients_in_api)
+ register(scenario_tests_need_service_tags)