diff options
author | Julien Danjou <julien@danjou.info> | 2014-08-25 15:05:50 +0200 |
---|---|---|
committer | Julien Danjou <julien@danjou.info> | 2014-08-26 11:30:24 +0200 |
commit | 48a9ba4e27bcf237f8b9032e70d79a3e22a429aa (patch) | |
tree | 5edc6033e9aa5205b54c73f02a8baad4d9799946 | |
parent | 1ee33509e7a6cfa2c9d6ae4f80cf0c3abdd4599b (diff) | |
download | oslo-messaging-48a9ba4e27bcf237f8b9032e70d79a3e22a429aa.tar.gz |
Fix Python 3 testing
Raising SkipTest at import time fails in recent version of the test
suite. We change that by being more picky at one should or should not be
tested based on what we managed to import; the upside is that we test a
few more things under Python 3 now.
Change-Id: I8971c7291cb261faf00fec73cf53b6132bdaf948
-rw-r--r-- | tests/drivers/test_impl_qpid.py | 7 | ||||
-rw-r--r-- | tests/executors/test_executor.py | 23 | ||||
-rw-r--r-- | tests/test_opts.py | 11 |
3 files changed, 25 insertions, 16 deletions
diff --git a/tests/drivers/test_impl_qpid.py b/tests/drivers/test_impl_qpid.py index e648d97..3c22794 100644 --- a/tests/drivers/test_impl_qpid.py +++ b/tests/drivers/test_impl_qpid.py @@ -16,15 +16,15 @@ import operator import random import threading import time -import unittest import mock try: import qpid except ImportError: - raise unittest.SkipTest("qpid not available") + qpid = None from six.moves import _thread import testscenarios +import testtools from oslo import messaging from oslo.messaging._drivers import impl_qpid as qpid_driver @@ -67,6 +67,7 @@ def _is_qpidd_service_running(): class _QpidBaseTestCase(test_utils.BaseTestCase): + @testtools.skipIf(qpid is None, "qpid not available") def setUp(self): super(_QpidBaseTestCase, self).setUp() self.messaging_conf.transport_driver = 'qpid' @@ -548,6 +549,7 @@ class TestQpidReconnectOrder(test_utils.BaseTestCase): """Unit Test cases to test reconnection """ + @testtools.skipIf(qpid is None, "qpid not available") def test_reconnect_order(self): brokers = ['host1', 'host2', 'host3', 'host4', 'host5'] brokers_count = len(brokers) @@ -768,6 +770,7 @@ def get_fake_qpid_session(): class QPidHATestCase(test_utils.BaseTestCase): + @testtools.skipIf(qpid is None, "qpid not available") def setUp(self): super(QPidHATestCase, self).setUp() self.brokers = ['host1', 'host2', 'host3', 'host4', 'host5'] diff --git a/tests/executors/test_executor.py b/tests/executors/test_executor.py index 3c04174..6b5b9bd 100644 --- a/tests/executors/test_executor.py +++ b/tests/executors/test_executor.py @@ -16,17 +16,20 @@ import contextlib import threading -import unittest try: import eventlet except ImportError: - raise unittest.SkipTest("Eventlet not available") + eventlet = None import mock import testscenarios +import testtools from oslo.messaging._executors import impl_blocking -from oslo.messaging._executors import impl_eventlet +try: + from oslo.messaging._executors import impl_eventlet +except ImportError: + impl_eventlet = None from tests import utils as test_utils load_tests = testscenarios.load_tests_apply_scenarios @@ -34,14 +37,15 @@ load_tests = testscenarios.load_tests_apply_scenarios class TestExecutor(test_utils.BaseTestCase): - _impl = [('blocking', dict(executor=impl_blocking.BlockingExecutor, - stop_before_return=True)), - ('eventlet', dict(executor=impl_eventlet.EventletExecutor, - stop_before_return=False))] - @classmethod def generate_scenarios(cls): - cls.scenarios = testscenarios.multiply_scenarios(cls._impl) + impl = [('blocking', dict(executor=impl_blocking.BlockingExecutor, + stop_before_return=True))] + if impl_eventlet is not None: + impl.append( + ('eventlet', dict(executor=impl_eventlet.EventletExecutor, + stop_before_return=False))) + cls.scenarios = testscenarios.multiply_scenarios(impl) @staticmethod def _run_in_thread(executor): @@ -90,6 +94,7 @@ class ExceptedException(Exception): class EventletContextManagerSpawnTest(test_utils.BaseTestCase): + @testtools.skipIf(impl_eventlet is None, "Eventlet not available") def setUp(self): super(EventletContextManagerSpawnTest, self).setUp() self.before = mock.Mock() diff --git a/tests/test_opts.py b/tests/test_opts.py index b3598c5..f8dec16 100644 --- a/tests/test_opts.py +++ b/tests/test_opts.py @@ -12,21 +12,22 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import unittest - import pkg_resources +import testtools try: from oslo.messaging import opts except ImportError: - import six - if six.PY3: - raise unittest.SkipTest + opts = None from tests import utils as test_utils class OptsTestCase(test_utils.BaseTestCase): + @testtools.skipIf(opts is None, "Options not importable") + def setUp(self): + super(OptsTestCase, self).setUp() + def _test_list_opts(self, result): self.assertEqual(3, len(result)) |