diff --git a/cloudinit/cmd/tests/test_clean.py b/cloudinit/cmd/tests/test_clean.py
index af438aa..cc19513 100644
--- a/cloudinit/cmd/tests/test_clean.py
+++ b/cloudinit/cmd/tests/test_clean.py
@@ -151,7 +151,7 @@ class TestClean(CiTestCase):
'sys.argv': {'new': ['clean', '--logs']}},
clean.main)
- self.assertEqual(0, context_manager.exception.code)
+ self.assertRaisesCodeEqual(0, context_manager.exception)
self.assertFalse(
os.path.exists(self.log1), 'Unexpected log {0}'.format(self.log1))
diff --git a/cloudinit/cmd/tests/test_status.py b/cloudinit/cmd/tests/test_status.py
index 8ec9b5b..5463fca 100644
--- a/cloudinit/cmd/tests/test_status.py
+++ b/cloudinit/cmd/tests/test_status.py
@@ -347,7 +347,7 @@ class TestStatus(CiTestCase):
'_is_cloudinit_disabled': (False, ''),
'Init': {'side_effect': self.init_class}},
status.main)
- self.assertEqual(0, context_manager.exception.code)
+ self.assertRaisesCodeEqual(0, context_manager.exception)
self.assertEqual('status: running\n', m_stdout.getvalue())
# vi: ts=4 expandtab syntax=python
diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py
index 1979cd9..5be0d64 100644
--- a/cloudinit/helpers.py
+++ b/cloudinit/helpers.py
@@ -449,4 +449,5 @@ class DefaultingConfigParser(RawConfigParser):
contents = '\n'.join([header, contents, ''])
return contents
+
# vi: ts=4 expandtab
diff --git a/cloudinit/tests/helpers.py b/cloudinit/tests/helpers.py
index feb884a..d10f536 100644
--- a/cloudinit/tests/helpers.py
+++ b/cloudinit/tests/helpers.py
@@ -158,6 +158,18 @@ class CiTestCase(TestCase):
dir = self.tmp_dir()
return os.path.normpath(os.path.abspath(os.path.join(dir, path)))
+ def assertRaisesCodeEqual(self, expected, found):
+ """Handle centos6 having different context manager for assertRaises.
+ with assertRaises(Exception) as e:
+ raise Exception("BOO")
+
+ centos6 will have e.exception as an integer.
+ anything nwere will have it as something with a '.code'"""
+ if isinstance(found, int):
+ self.assertEqual(expected, found)
+ else:
+ self.assertEqual(expected, found.code)
+
class ResourceUsingTestCase(CiTestCase):
@@ -395,4 +407,8 @@ if not hasattr(mock.Mock, 'assert_not_called'):
mock.Mock.assert_not_called = __mock_assert_not_called
+# older unittest2.TestCase (centos6) do not have assertRaisesRegex
+if not hasattr(unittest2.TestCase, 'assertRaisesRegex'):
+ unittest2.TestCase.assertRaisesRegex = unittest2.TestCase.assertRaisesRegexp
+
# vi: ts=4 expandtab
diff --git a/tox.ini b/tox.ini
index d7316cc..11aa063 100644
--- a/tox.ini
+++ b/tox.ini
@@ -21,7 +21,7 @@ setenv =
LC_ALL = en_US.utf-8
[testenv:pylint]
-basepython = python3
+basepython = python
deps =
# requirements
pylint==1.7.1