From ee4a2a4bb7c70d836d368d3866acaedae63fd578 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Fri, 3 Jul 2015 11:16:01 +0200 Subject: [PATCH] Port test_exception to Python 3 * FakeNovaException_Remote: on Python 3, define a __str__() method instead of __unicode__() method. str(exc) now calls __str__() now Pyton 3, __unicode__() is no more used. * tox.ini: add nova.tests.unit.test_exception to Python 3. Blueprint nova-python3 Change-Id: Ia3e3f253aa57b75a47f3ba044d2c539f9ce48aea --- nova/tests/unit/test_exception.py | 8 ++++++-- tox.ini | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/test_exception.py b/nova/tests/unit/test_exception.py index 6b1617047c..3b54f485d9 100644 --- a/nova/tests/unit/test_exception.py +++ b/nova/tests/unit/test_exception.py @@ -123,8 +123,12 @@ class NovaExceptionTestCase(test.NoDBTestCase): class FakeNovaException_Remote(exception.NovaException): msg_fmt = "some message" - def __unicode__(self): - return u"print the whole trace" + if six.PY3: + def __str__(self): + return "print the whole trace" + else: + def __unicode__(self): + return u"print the whole trace" exc = FakeNovaException_Remote() self.assertEqual(six.text_type(exc), u"print the whole trace") diff --git a/tox.ini b/tox.ini index 5e55830aeb..875a453617 100644 --- a/tox.ini +++ b/tox.ini @@ -43,6 +43,7 @@ deps = -r{toxinidir}/requirements.txt commands = find . -type f -name "*.pyc" -delete python -m testtools.run \ + nova.tests.unit.test_exception \ nova.tests.unit.db.test_db_api \ nova.tests.unit.test_versions