Skip to content

Commit

Permalink
Merge "Add hacking check for testtools.skip"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 7, 2015
2 parents e6834f8 + 3059a09 commit 9c0bb46
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions HACKING.rst
Expand Up @@ -15,6 +15,8 @@ Tempest Specific Commandments
- [T106] vim configuration should not be kept in source files.
- [T107] Check that a service tag isn't in the module path
- [T108] Check no hyphen at the end of rand_name() argument
- [T109] Cannot use testtools.skip decorator; instead use
decorators.skip_because from tempest-lib
- [N322] Method's default argument shouldn't be mutable

Test Data/Configuration
Expand Down
12 changes: 12 additions & 0 deletions tempest/hacking/checks.py
Expand Up @@ -29,6 +29,7 @@
VI_HEADER_RE = re.compile(r"^#\s+vim?:.+")
RAND_NAME_HYPHEN_RE = re.compile(r".*rand_name\(.+[\-\_][\"\']\)")
mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])")
TESTTOOLS_SKIP_DECORATOR = re.compile(r'\s*@testtools\.skip\((.*)\)')


def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
Expand Down Expand Up @@ -132,6 +133,16 @@ def no_mutable_default_args(logical_line):
yield (0, msg)


def no_testtools_skip_decorator(logical_line):
"""Check that methods do not have the testtools.skip decorator
T109
"""
if TESTTOOLS_SKIP_DECORATOR.match(logical_line):
yield (0, "T109: Cannot use testtools.skip decorator; instead use "
"decorators.skip_because from tempest-lib")


def factory(register):
register(import_no_clients_in_api_and_scenario_tests)
register(scenario_tests_need_service_tags)
Expand All @@ -140,3 +151,4 @@ def factory(register):
register(service_tags_not_in_module_path)
register(no_hyphen_at_end_of_rand_name)
register(no_mutable_default_args)
register(no_testtools_skip_decorator)
8 changes: 8 additions & 0 deletions tempest/tests/test_hacking.py
Expand Up @@ -138,3 +138,11 @@ def test_no_mutable_default_args(self):

self.assertEqual(0, len(list(checks.no_mutable_default_args(
"defined, undefined = [], {}"))))

def test_no_testtools_skip_decorator(self):
self.assertEqual(1, len(list(checks.no_testtools_skip_decorator(
" @testtools.skip('Bug xxx')"))))
self.assertEqual(0, len(list(checks.no_testtools_skip_decorator(
" @testtools.skipUnless(CONF.something, 'msg')"))))
self.assertEqual(0, len(list(checks.no_testtools_skip_decorator(
" @testtools.skipIf(CONF.something, 'msg')"))))

0 comments on commit 9c0bb46

Please sign in to comment.