This gives a better test output on what has been skipped and why.
The unittest2.TestCase class has been removed because it is unused and
unittest2 is not available to the gates.
Change-Id: I1b5ae0845b2ef8dadc5cff42770ef062ea4e862f
from nose import with_setup
import unittest
import shutil
-from nose.exc import SkipTest
+
+from utils import skip_if
+
try:
from heat.cfntools.cfn_helper import *
except:
- raise SkipTest("unable to import cfn helper, skipping")
+ skip_test = True
+else:
+ skip_test = False
@attr(tag=['unit', 'cfn_helper'])
@attr(speed='fast')
+@skip_if(skip_test, 'unable to import cfn_helper')
def test_boolean():
assert(to_boolean('true'))
@with_setup(setUp_credential_file, tearDown_credential_file)
@attr(tag=['unit', 'cfn-hup'])
@attr(speed='fast')
+@skip_if(skip_test, 'unable to import cfn_helper')
def test_hup_conf1():
good = """
[main]
@with_setup(setUp_credential_file, tearDown_credential_file)
@attr(tag=['unit', 'cfn-hup'])
@attr(speed='fast')
+@skip_if(skip_test, 'unable to import cfn_helper')
def test_hup_default():
good = """
[main]
@with_setup(setUp_credential_file, tearDown_credential_file)
@attr(tag=['unit', 'cfn-hup'])
@attr(speed='fast')
+@skip_if(skip_test, 'unable to import cfn_helper')
def test_hup_hook():
good = """
[main]
@attr(tag=['unit', 'cfn-metadata'])
@attr(speed='fast')
+ @skip_if(skip_test, 'unable to import cfn_helper')
def test_metadata_files(self):
j = ''' {
"AWS::CloudFormation::Init" : {
@attr(tag=['unit', 'cfn-helper'])
@attr(speed='fast')
+ @skip_if(skip_test, 'unable to import cfn_helper')
def test_runas(self):
import subprocess
self.m.StubOutWithMock(subprocess, 'Popen')
@attr(tag=['unit', 'cfn-helper'])
@attr(speed='fast')
+ @skip_if(skip_test, 'unable to import cfn_helper')
def test_default_runas(self):
import subprocess
self.m.StubOutWithMock(subprocess, 'Popen')
from heat.engine import s3
from heat.engine import parser
-from nose.exc import SkipTest
+from utils import skip_if
+
try:
- from swiftclient import client as swiftclient
+ from swiftclients import client as swiftclient
except:
- raise SkipTest("unable to import swiftclient, skipping")
+ skip_test = True
+else:
+ skip_test = False
@attr(tag=['unit', 'resource'])
@attr(speed='fast')
class s3Test(unittest.TestCase):
+ @skip_if(skip_test, 'unable to import swiftclient')
def setUp(self):
self.m = mox.Mox()
self.m.CreateMock(swiftclient.Connection)
self.assertEqual(s3.S3Bucket.CREATE_COMPLETE, resource.state)
return resource
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_create_container_name(self):
self.m.UnsetStubs()
self.assertTrue(re.match(self.container_pattern,
s3.S3Bucket._create_container_name('test_stack.test_resource')))
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_attributes(self):
swiftclient.Connection.put_container(
mox.Regex(self.container_pattern),
resource.delete()
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_public_read(self):
swiftclient.Connection.put_container(
mox.Regex(self.container_pattern),
resource.delete()
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_public_read_write(self):
swiftclient.Connection.put_container(
mox.Regex(self.container_pattern),
resource.delete()
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_authenticated_read(self):
swiftclient.Connection.put_container(
mox.Regex(self.container_pattern),
resource.delete()
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_website(self):
swiftclient.Connection.put_container(
resource.delete()
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_delete_exception(self):
swiftclient.Connection.put_container(
self.m.VerifyAll()
+ @skip_if(skip_test, 'unable to import swiftclient')
def test_delete_retain(self):
# first run, with retain policy
# under the License.
-import unittest2
+import nose.plugins.skip as skip
-class TestCase(unittest2.TestCase):
- pass
+class skip_test(object):
+ """Decorator that skips a test."""
+ def __init__(self, msg):
+ self.message = msg
+
+ def __call__(self, func):
+ def _skipper(*args, **kw):
+ """Wrapped skipper function."""
+ raise skip.SkipTest(self.message)
+ _skipper.__name__ = func.__name__
+ _skipper.__doc__ = func.__doc__
+ return _skipper
+
+
+class skip_if(object):
+ """Decorator that skips a test if condition is true."""
+ def __init__(self, condition, msg):
+ self.condition = condition
+ self.message = msg
+
+ def __call__(self, func):
+ def _skipper(*args, **kw):
+ """Wrapped skipper function."""
+ if self.condition:
+ raise skip.SkipTest(self.message)
+ func(*args, **kw)
+ _skipper.__name__ = func.__name__
+ _skipper.__doc__ = func.__doc__
+ return _skipper
+
+
+class skip_unless(object):
+ """Decorator that skips a test if condition is not true."""
+ def __init__(self, condition, msg):
+ self.condition = condition
+ self.message = msg
+
+ def __call__(self, func):
+ def _skipper(*args, **kw):
+ """Wrapped skipper function."""
+ if not self.condition:
+ raise skip.SkipTest(self.message)
+ func(*args, **kw)
+ _skipper.__name__ = func.__name__
+ _skipper.__doc__ = func.__doc__
+ return _skipper