Unsupported 'message' Exception attribute in PY3
* Fix unsupported 'message' Exception attribute in PY3 The 'message' attribute has been deprecated and removed from Python3. Use six.text_type(e) instead of e.message. For more details, please check [1]: [1] https://www.python.org/dev/peps/pep-0352/ * Add hacking to prevent this from happening in the future. Change-Id: Id40000c2c453815b04a7d2fd765e19997291d8e3
This commit is contained in:
parent
0252bca0d9
commit
bc2ae8629c
@ -24,6 +24,7 @@ Tempest Specific Commandments
|
|||||||
- [T114] Check that tempest.lib does not use tempest config
|
- [T114] Check that tempest.lib does not use tempest config
|
||||||
- [T115] Check that admin tests should exist under admin path
|
- [T115] Check that admin tests should exist under admin path
|
||||||
- [N322] Method's default argument shouldn't be mutable
|
- [N322] Method's default argument shouldn't be mutable
|
||||||
|
- [T116] Unsupported 'message' Exception attribute in PY3
|
||||||
|
|
||||||
Test Data/Configuration
|
Test Data/Configuration
|
||||||
-----------------------
|
-----------------------
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
from tempest.api.compute import base
|
from tempest.api.compute import base
|
||||||
from tempest.common import compute
|
from tempest.common import compute
|
||||||
from tempest.common.utils import net_utils
|
from tempest.common.utils import net_utils
|
||||||
@ -195,7 +197,7 @@ class AttachInterfacesTestJSON(base.BaseV2ComputeTest):
|
|||||||
except lib_exc.BadRequest as e:
|
except lib_exc.BadRequest as e:
|
||||||
msg = ('Multiple possible networks found, use a Network ID to be '
|
msg = ('Multiple possible networks found, use a Network ID to be '
|
||||||
'more specific.')
|
'more specific.')
|
||||||
if not CONF.compute.fixed_network_name and e.message == msg:
|
if not CONF.compute.fixed_network_name and six.text_type(e) == msg:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
ifs.append(iface)
|
ifs.append(iface)
|
||||||
|
@ -33,6 +33,7 @@ METHOD = re.compile(r"^ def .+")
|
|||||||
METHOD_GET_RESOURCE = re.compile(r"^\s*def (list|show)\_.+")
|
METHOD_GET_RESOURCE = re.compile(r"^\s*def (list|show)\_.+")
|
||||||
METHOD_DELETE_RESOURCE = re.compile(r"^\s*def delete_.+")
|
METHOD_DELETE_RESOURCE = re.compile(r"^\s*def delete_.+")
|
||||||
CLASS = re.compile(r"^class .+")
|
CLASS = re.compile(r"^class .+")
|
||||||
|
EX_ATTRIBUTE = re.compile(r'(\s+|\()(e|ex|exc|exception).message(\s+|\))')
|
||||||
|
|
||||||
|
|
||||||
def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
|
def import_no_clients_in_api_and_scenario_tests(physical_line, filename):
|
||||||
@ -294,6 +295,17 @@ def dont_put_admin_tests_on_nonadmin_path(logical_line, physical_line,
|
|||||||
yield(0, msg)
|
yield(0, msg)
|
||||||
|
|
||||||
|
|
||||||
|
def unsupported_exception_attribute_PY3(logical_line):
|
||||||
|
"""Check Unsupported 'message' exception attribute in PY3
|
||||||
|
|
||||||
|
T116
|
||||||
|
"""
|
||||||
|
result = EX_ATTRIBUTE.search(logical_line)
|
||||||
|
msg = ("[T116] Unsupported 'message' Exception attribute in PY3")
|
||||||
|
if result:
|
||||||
|
yield(0, msg)
|
||||||
|
|
||||||
|
|
||||||
def factory(register):
|
def factory(register):
|
||||||
register(import_no_clients_in_api_and_scenario_tests)
|
register(import_no_clients_in_api_and_scenario_tests)
|
||||||
register(scenario_tests_need_service_tags)
|
register(scenario_tests_need_service_tags)
|
||||||
@ -309,3 +321,4 @@ def factory(register):
|
|||||||
register(dont_use_config_in_tempest_lib)
|
register(dont_use_config_in_tempest_lib)
|
||||||
register(use_rand_uuid_instead_of_uuid4)
|
register(use_rand_uuid_instead_of_uuid4)
|
||||||
register(dont_put_admin_tests_on_nonadmin_path)
|
register(dont_put_admin_tests_on_nonadmin_path)
|
||||||
|
register(unsupported_exception_attribute_PY3)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import six
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from tempest.lib.common import api_version_utils
|
from tempest.lib.common import api_version_utils
|
||||||
@ -30,7 +31,7 @@ class TestVersionSkipLogic(base.TestCase):
|
|||||||
cfg_max_version)
|
cfg_max_version)
|
||||||
except testtools.TestCase.skipException as e:
|
except testtools.TestCase.skipException as e:
|
||||||
if not expected_skip:
|
if not expected_skip:
|
||||||
raise testtools.TestCase.failureException(e.message)
|
raise testtools.TestCase.failureException(six.text_type(e))
|
||||||
|
|
||||||
def test_version_min_in_range(self):
|
def test_version_min_in_range(self):
|
||||||
self._test_version('2.2', '2.10', '2.1', '2.7')
|
self._test_version('2.2', '2.10', '2.1', '2.7')
|
||||||
|
@ -180,3 +180,15 @@ class HackingTestCase(base.TestCase):
|
|||||||
'from oslo_config import cfg', './tempest/lib/decorators.py')))
|
'from oslo_config import cfg', './tempest/lib/decorators.py')))
|
||||||
self.assertTrue(list(checks.dont_use_config_in_tempest_lib(
|
self.assertTrue(list(checks.dont_use_config_in_tempest_lib(
|
||||||
'import tempest.config', './tempest/lib/common/rest_client.py')))
|
'import tempest.config', './tempest/lib/common/rest_client.py')))
|
||||||
|
|
||||||
|
def test_unsupported_exception_attribute_PY3(self):
|
||||||
|
self.assertEqual(len(list(checks.unsupported_exception_attribute_PY3(
|
||||||
|
"raise TestCase.failureException(e.message)"))), 1)
|
||||||
|
self.assertEqual(len(list(checks.unsupported_exception_attribute_PY3(
|
||||||
|
"raise TestCase.failureException(ex.message)"))), 1)
|
||||||
|
self.assertEqual(len(list(checks.unsupported_exception_attribute_PY3(
|
||||||
|
"raise TestCase.failureException(exc.message)"))), 1)
|
||||||
|
self.assertEqual(len(list(checks.unsupported_exception_attribute_PY3(
|
||||||
|
"raise TestCase.failureException(exception.message)"))), 1)
|
||||||
|
self.assertEqual(len(list(checks.unsupported_exception_attribute_PY3(
|
||||||
|
"raise TestCase.failureException(ee.message)"))), 0)
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
import six
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from tempest.api.compute import base as compute_base
|
from tempest.api.compute import base as compute_base
|
||||||
@ -74,7 +75,7 @@ class TestMicroversionsTestsClass(base.TestCase):
|
|||||||
self.assertRaises(testtools.TestCase.skipException,
|
self.assertRaises(testtools.TestCase.skipException,
|
||||||
test_class.skip_checks)
|
test_class.skip_checks)
|
||||||
except testtools.TestCase.skipException as e:
|
except testtools.TestCase.skipException as e:
|
||||||
raise testtools.TestCase.failureException(e.message)
|
raise testtools.TestCase.failureException(six.text_type(e))
|
||||||
|
|
||||||
def test_config_version_none_none(self):
|
def test_config_version_none_none(self):
|
||||||
expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2]
|
expected_pass_tests = [VersionTestNoneTolatest, VersionTestNoneTo2_2]
|
||||||
|
Loading…
Reference in New Issue
Block a user