No longer import nose
Since Python 2.7, unittest in the standard library has included mulitple facilities for skipping tests by decorators as well as an exception. Switch to that directly, rather than importing nose. Change-Id: I4009033473ea24f0d0faed3670db844f40051f30
This commit is contained in:
parent
13116fefd8
commit
5a06e3da3b
@ -103,8 +103,8 @@ swift_test_domain = ['', '', '', '', '', '']
|
||||
swift_test_user_id = ['', '', '', '', '', '']
|
||||
swift_test_tenant_id = ['', '', '', '', '', '']
|
||||
|
||||
skip, skip2, skip3, skip_service_tokens, skip_if_no_reseller_admin = \
|
||||
False, False, False, False, False
|
||||
skip, skip2, skip3, skip_if_not_v3, skip_service_tokens, \
|
||||
skip_if_no_reseller_admin = False, False, False, False, False, False
|
||||
|
||||
orig_collate = ''
|
||||
insecure = False
|
||||
|
@ -20,7 +20,6 @@ import uuid
|
||||
from random import shuffle
|
||||
|
||||
from keystoneclient.v3 import client
|
||||
from nose import SkipTest
|
||||
from swiftclient import get_auth, http_connection
|
||||
|
||||
import test.functional as tf
|
||||
@ -3223,7 +3222,7 @@ class TestRBAC(BaseTestAC):
|
||||
def test_rbac(self):
|
||||
if any((tf.skip, tf.skip2, tf.skip3, tf.skip_if_not_v3,
|
||||
tf.skip_if_no_reseller_admin)):
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
scenario_rbac = RBAC_PUT + RBAC_DELETE + RBAC_GET +\
|
||||
RBAC_HEAD + RBAC_POST + RBAC_OPTIONS
|
||||
shuffle(scenario_rbac)
|
||||
@ -3232,7 +3231,7 @@ class TestRBAC(BaseTestAC):
|
||||
def test_rbac_with_service_prefix(self):
|
||||
if any((tf.skip, tf.skip2, tf.skip3, tf.skip_if_not_v3,
|
||||
tf.skip_service_tokens, tf.skip_if_no_reseller_admin)):
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
scenario_rbac = RBAC_PUT_WITH_SERVICE_PREFIX +\
|
||||
RBAC_DELETE_WITH_SERVICE_PREFIX +\
|
||||
RBAC_GET_WITH_SERVICE_PREFIX +\
|
||||
@ -3271,7 +3270,7 @@ class TestRBACInfo(BaseTestAC):
|
||||
def test_rbac_info(self):
|
||||
if any((tf.skip, tf.skip2, tf.skip3, tf.skip_if_not_v3,
|
||||
tf.skip_if_no_reseller_admin)):
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
self.info_url = self._get_info_url()
|
||||
scenario_rbac_info = RBAC_INFO_GET + RBAC_INFO_HEAD + RBAC_INFO_OPTIONS
|
||||
shuffle(scenario_rbac_info)
|
||||
@ -3280,7 +3279,7 @@ class TestRBACInfo(BaseTestAC):
|
||||
def test_rbac_info_with_service_prefix(self):
|
||||
if any((tf.skip, tf.skip2, tf.skip3, tf.skip_if_not_v3,
|
||||
tf.skip_service_tokens, tf.skip_if_no_reseller_admin)):
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
self.info_url = self._get_info_url()
|
||||
scenario_rbac_info = RBAC_INFO_GET_WITH_SERVICE_PREFIX +\
|
||||
RBAC_INFO_HEAD_WITH_SERVICE_PREFIX +\
|
||||
@ -3302,7 +3301,7 @@ class TestContainerACL(BaseTestAC):
|
||||
def test_container_acl(self):
|
||||
if any((tf.skip, tf.skip2, tf.skip3, tf.skip_if_not_v3,
|
||||
tf.skip_if_no_reseller_admin)):
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
self.id_info = KeystoneClient().get_id_info()
|
||||
scenario_container_acl = ACL_PUT + ACL_DELETE + ACL_GET +\
|
||||
ACL_HEAD + ACL_POST + ACL_OPTIONS
|
||||
|
@ -24,7 +24,6 @@ from collections import defaultdict
|
||||
import unittest
|
||||
from hashlib import md5
|
||||
from uuid import uuid4
|
||||
from nose import SkipTest
|
||||
|
||||
from six.moves.http_client import HTTPConnection
|
||||
import shutil
|
||||
@ -204,12 +203,12 @@ def get_ring(ring_name, required_replicas, required_devices,
|
||||
return ring
|
||||
# easy sanity checks
|
||||
if ring.replica_count != required_replicas:
|
||||
raise SkipTest('%s has %s replicas instead of %s' % (
|
||||
raise unittest.SkipTest('%s has %s replicas instead of %s' % (
|
||||
ring.serialized_path, ring.replica_count, required_replicas))
|
||||
|
||||
devs = [dev for dev in ring.devs if dev is not None]
|
||||
if len(devs) != required_devices:
|
||||
raise SkipTest('%s has %s devices instead of %s' % (
|
||||
raise unittest.SkipTest('%s has %s devices instead of %s' % (
|
||||
ring.serialized_path, len(devs), required_devices))
|
||||
for dev in devs:
|
||||
# verify server is exposing mounted device
|
||||
@ -221,12 +220,12 @@ def get_ring(ring_name, required_replicas, required_devices,
|
||||
dev_path = os.path.join(conf['devices'], device)
|
||||
full_path = os.path.realpath(dev_path)
|
||||
if not os.path.exists(full_path):
|
||||
raise SkipTest(
|
||||
raise unittest.SkipTest(
|
||||
'device %s in %s was not found (%s)' %
|
||||
(device, conf['devices'], full_path))
|
||||
break
|
||||
else:
|
||||
raise SkipTest(
|
||||
raise unittest.SkipTest(
|
||||
"unable to find ring device %s under %s's devices (%s)" % (
|
||||
dev['device'], server, conf['devices']))
|
||||
# verify server is exposing rsync device
|
||||
@ -237,14 +236,14 @@ def get_ring(ring_name, required_replicas, required_devices,
|
||||
p = Popen(cmd, shell=True, stdout=PIPE)
|
||||
stdout, _stderr = p.communicate()
|
||||
if p.returncode:
|
||||
raise SkipTest('unable to connect to rsync '
|
||||
raise unittest.SkipTest('unable to connect to rsync '
|
||||
'export %s (%s)' % (rsync_export, cmd))
|
||||
for line in stdout.splitlines():
|
||||
if line.rsplit(None, 1)[-1] == dev['device']:
|
||||
break
|
||||
else:
|
||||
raise SkipTest("unable to find ring device %s under rsync's "
|
||||
"exported devices for %s (%s)" %
|
||||
raise unittest.SkipTest("unable to find ring device %s under "
|
||||
"rsync's exported devices for %s (%s)" %
|
||||
(dev['device'], rsync_export, cmd))
|
||||
return ring
|
||||
|
||||
@ -264,7 +263,7 @@ def get_policy(**kwargs):
|
||||
matches = False
|
||||
if matches:
|
||||
return policy
|
||||
raise SkipTest('No policy matching %s' % kwargs)
|
||||
raise unittest.SkipTest('No policy matching %s' % kwargs)
|
||||
|
||||
|
||||
def resetswift():
|
||||
@ -501,13 +500,13 @@ if __name__ == "__main__":
|
||||
try:
|
||||
get_ring(server, 3, 4,
|
||||
force_validate=True)
|
||||
except SkipTest as err:
|
||||
except unittest.SkipTest as err:
|
||||
sys.exit('%s ERROR: %s' % (server, err))
|
||||
print('%s OK' % server)
|
||||
for policy in POLICIES:
|
||||
try:
|
||||
get_ring(policy.ring_name, 3, 4,
|
||||
server='object', force_validate=True)
|
||||
except SkipTest as err:
|
||||
except unittest.SkipTest as err:
|
||||
sys.exit('object ERROR (%s): %s' % (policy.name, err))
|
||||
print('object OK (%s)' % policy.name)
|
||||
|
@ -18,8 +18,6 @@ import uuid
|
||||
import random
|
||||
import unittest
|
||||
|
||||
from nose import SkipTest
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
from swift.common.manager import Manager
|
||||
from swift.common.internal_client import InternalClient
|
||||
@ -37,9 +35,8 @@ TIMEOUT = 60
|
||||
|
||||
class TestContainerMergePolicyIndex(ReplProbeTest):
|
||||
|
||||
@unittest.skipIf(len(ENABLED_POLICIES) < 2, "Need more than one policy")
|
||||
def setUp(self):
|
||||
if len(ENABLED_POLICIES) < 2:
|
||||
raise SkipTest('Need more than one policy')
|
||||
super(TestContainerMergePolicyIndex, self).setUp()
|
||||
self.container_name = 'container-%s' % uuid.uuid4()
|
||||
self.object_name = 'object-%s' % uuid.uuid4()
|
||||
@ -247,10 +244,10 @@ class TestContainerMergePolicyIndex(ReplProbeTest):
|
||||
urlparse(self.url).netloc)
|
||||
proxy_conn = client.http_connection(info_url)
|
||||
cluster_info = client.get_capabilities(proxy_conn)
|
||||
if 'slo' not in cluster_info:
|
||||
raise SkipTest("SLO not enabled in proxy; "
|
||||
"can't test manifest reconciliation")
|
||||
|
||||
if 'slo' not in cluster_info:
|
||||
raise unittest.SkipTest(
|
||||
"SLO not enabled in proxy; can't test manifest reconciliation")
|
||||
# this test is not only testing a split brain scenario on
|
||||
# multiple policies with mis-placed objects - it even writes out
|
||||
# a static large object directly to the storage nodes while the
|
||||
|
@ -14,7 +14,6 @@
|
||||
import json
|
||||
import uuid
|
||||
import random
|
||||
from nose import SkipTest
|
||||
import unittest
|
||||
|
||||
from six.moves.urllib.parse import urlparse
|
||||
@ -33,16 +32,16 @@ def get_current_realm_cluster(url):
|
||||
try:
|
||||
info = client.get_capabilities(http_conn)
|
||||
except client.ClientException:
|
||||
raise SkipTest('Unable to retrieve cluster info')
|
||||
raise unittest.SkipTest('Unable to retrieve cluster info')
|
||||
try:
|
||||
realms = info['container_sync']['realms']
|
||||
except KeyError:
|
||||
raise SkipTest('Unable to find container sync realms')
|
||||
raise unittest.SkipTest('Unable to find container sync realms')
|
||||
for realm, realm_info in realms.items():
|
||||
for cluster, options in realm_info['clusters'].items():
|
||||
if options.get('current', False):
|
||||
return realm, cluster
|
||||
raise SkipTest('Unable find current realm cluster')
|
||||
raise unittest.SkipTest('Unable find current realm cluster')
|
||||
|
||||
|
||||
class TestContainerSync(ReplProbeTest):
|
||||
|
@ -15,11 +15,9 @@
|
||||
# limitations under the License.
|
||||
|
||||
from io import StringIO
|
||||
from unittest import main
|
||||
from unittest import main, SkipTest
|
||||
from uuid import uuid4
|
||||
|
||||
from nose import SkipTest
|
||||
|
||||
from swiftclient import client
|
||||
from swiftclient.exceptions import ClientException
|
||||
|
||||
@ -65,7 +63,7 @@ class TestObjectAsyncUpdate(ReplProbeTest):
|
||||
# In this test, we need to put container at handoff devices, so we
|
||||
# need container devices more than replica count
|
||||
if len(self.container_ring.devs) <= self.container_ring.replica_count:
|
||||
raise SkipTest('Need devices more that replica count')
|
||||
raise SkipTest("Need devices more that replica count")
|
||||
|
||||
container = 'container-%s' % uuid4()
|
||||
cpart, cnodes = self.container_ring.get_nodes(self.account, container)
|
||||
|
@ -17,8 +17,6 @@ import time
|
||||
import uuid
|
||||
import unittest
|
||||
|
||||
from nose import SkipTest
|
||||
|
||||
from swift.common.internal_client import InternalClient, UnexpectedResponse
|
||||
from swift.common.manager import Manager
|
||||
from swift.common.utils import Timestamp
|
||||
@ -36,7 +34,7 @@ class TestObjectExpirer(ReplProbeTest):
|
||||
self.expirer.start()
|
||||
err = self.expirer.stop()
|
||||
if err:
|
||||
raise SkipTest('Unable to verify object-expirer service')
|
||||
raise unittest.SkipTest('Unable to verify object-expirer service')
|
||||
|
||||
conf_files = []
|
||||
for server in self.expirer.servers:
|
||||
@ -59,10 +57,8 @@ class TestObjectExpirer(ReplProbeTest):
|
||||
|
||||
return False
|
||||
|
||||
@unittest.skipIf(len(ENABLED_POLICIES) < 2, "Need more than one policy")
|
||||
def test_expirer_object_split_brain(self):
|
||||
if len(ENABLED_POLICIES) < 2:
|
||||
raise SkipTest('Need more than one policy')
|
||||
|
||||
old_policy = random.choice(ENABLED_POLICIES)
|
||||
wrong_policy = random.choice([p for p in ENABLED_POLICIES
|
||||
if p != old_policy])
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
from nose import SkipTest
|
||||
|
||||
try:
|
||||
# this test requires the dnspython package to be installed
|
||||
@ -50,9 +49,8 @@ def start_response(*args):
|
||||
|
||||
class TestCNAMELookup(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(skip, "can't import dnspython")
|
||||
def setUp(self):
|
||||
if skip:
|
||||
raise SkipTest
|
||||
self.app = cname_lookup.CNAMELookupMiddleware(FakeApp(),
|
||||
{'lookup_depth': 2})
|
||||
|
||||
|
@ -18,7 +18,6 @@ import json
|
||||
import shutil
|
||||
import tempfile
|
||||
import unittest
|
||||
from nose import SkipTest
|
||||
|
||||
from six import BytesIO
|
||||
|
||||
@ -49,9 +48,8 @@ class FakeApp(object):
|
||||
|
||||
class TestXProfile(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def test_get_profiler(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
self.assertTrue(xprofile.get_profiler('cProfile') is not None)
|
||||
self.assertTrue(xprofile.get_profiler('eventlet.green.profile')
|
||||
is not None)
|
||||
@ -59,9 +57,8 @@ class TestXProfile(unittest.TestCase):
|
||||
|
||||
class TestProfilers(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def setUp(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
self.profilers = [xprofile.get_profiler('cProfile'),
|
||||
xprofile.get_profiler('eventlet.green.profile')]
|
||||
|
||||
@ -83,9 +80,8 @@ class TestProfilers(unittest.TestCase):
|
||||
|
||||
class TestProfileMiddleware(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def setUp(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
self.got_statuses = []
|
||||
self.app = ProfileMiddleware(FakeApp, {})
|
||||
self.tempdir = os.path.dirname(self.app.log_filename_prefix)
|
||||
@ -191,10 +187,8 @@ class TestProfileMiddleware(unittest.TestCase):
|
||||
|
||||
class Test_profile_log(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def setUp(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
|
||||
self.dir1 = tempfile.mkdtemp()
|
||||
self.log_filename_prefix1 = self.dir1 + '/unittest.profile'
|
||||
self.profile_log1 = ProfileLog(self.log_filename_prefix1, False)
|
||||
@ -282,9 +276,8 @@ class Test_profile_log(unittest.TestCase):
|
||||
|
||||
class Test_html_viewer(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def setUp(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
self.app = ProfileMiddleware(FakeApp, {})
|
||||
self.log_files = []
|
||||
self.tempdir = tempfile.mkdtemp()
|
||||
@ -473,9 +466,8 @@ class Test_html_viewer(unittest.TestCase):
|
||||
|
||||
class TestStats2(unittest.TestCase):
|
||||
|
||||
@unittest.skipIf(xprofile is None, "can't import xprofile")
|
||||
def setUp(self):
|
||||
if xprofile is None:
|
||||
raise SkipTest
|
||||
self.profile_file = tempfile.mktemp('profile', 'unittest')
|
||||
self.profilers = [xprofile.get_profiler('cProfile'),
|
||||
xprofile.get_profiler('eventlet.green.profile')]
|
||||
|
@ -25,7 +25,6 @@ import contextlib
|
||||
import re
|
||||
|
||||
import mock
|
||||
import nose
|
||||
import six
|
||||
|
||||
from swift.common.splice import splice, tee
|
||||
@ -73,7 +72,7 @@ class TestSplice(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
if not splice.available:
|
||||
raise nose.SkipTest('splice not available')
|
||||
raise unittest.SkipTest('splice not available')
|
||||
|
||||
def test_flags(self):
|
||||
'''Test flag attribute availability'''
|
||||
@ -228,7 +227,7 @@ class TestTee(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
if not tee.available:
|
||||
raise nose.SkipTest('tee not available')
|
||||
raise unittest.SkipTest('tee not available')
|
||||
|
||||
@mock.patch('swift.common.splice.tee._c_tee', None)
|
||||
def test_available(self):
|
||||
|
@ -57,7 +57,6 @@ from functools import partial
|
||||
from tempfile import TemporaryFile, NamedTemporaryFile, mkdtemp
|
||||
from netifaces import AF_INET6
|
||||
from mock import MagicMock, patch
|
||||
from nose import SkipTest
|
||||
from six.moves.configparser import NoSectionError, NoOptionError
|
||||
from uuid import uuid4
|
||||
|
||||
@ -3697,7 +3696,7 @@ cluster_dfw1 = http://dfw1.host/v1/
|
||||
try:
|
||||
utils.NR_ioprio_set()
|
||||
except OSError as e:
|
||||
raise SkipTest(e)
|
||||
raise unittest.SkipTest(e)
|
||||
|
||||
with patch('swift.common.utils._libc_setpriority',
|
||||
_fake_setpriority), \
|
||||
|
@ -31,7 +31,6 @@ if six.PY2:
|
||||
import mimetools
|
||||
|
||||
import mock
|
||||
import nose
|
||||
|
||||
import swift.common.middleware.catch_errors
|
||||
import swift.common.middleware.gatekeeper
|
||||
@ -75,10 +74,8 @@ class TestWSGI(unittest.TestCase):
|
||||
if six.PY2:
|
||||
mimetools.Message.parsetype = self._orig_parsetype
|
||||
|
||||
@unittest.skipIf(six.PY3, "test specific to Python 2")
|
||||
def test_monkey_patch_mimetools(self):
|
||||
if six.PY3:
|
||||
raise nose.SkipTest('test specific to Python 2')
|
||||
|
||||
sio = StringIO('blah')
|
||||
self.assertEqual(mimetools.Message(sio).type, 'text/plain')
|
||||
sio = StringIO('blah')
|
||||
|
@ -46,7 +46,6 @@ from test.unit import (mock as unit_mock, temptree, mock_check_drive,
|
||||
make_timestamp_iter, DEFAULT_TEST_EC_TYPE,
|
||||
requires_o_tmpfile_support, encode_frag_archive_bodies,
|
||||
skip_if_no_xattrs)
|
||||
from nose import SkipTest
|
||||
from swift.obj import diskfile
|
||||
from swift.common import utils
|
||||
from swift.common.utils import hash_path, mkdirs, Timestamp, \
|
||||
@ -4746,8 +4745,7 @@ class DiskFileMixin(BaseDiskFileTestMixin):
|
||||
|
||||
def test_zero_copy_cache_dropping(self):
|
||||
if not self._system_can_zero_copy():
|
||||
raise SkipTest("zero-copy support is missing")
|
||||
|
||||
raise unittest.SkipTest("zero-copy support is missing")
|
||||
self.conf['splice'] = 'on'
|
||||
self.conf['keep_cache_size'] = 16384
|
||||
self.conf['disk_chunk_size'] = 4096
|
||||
@ -4767,7 +4765,7 @@ class DiskFileMixin(BaseDiskFileTestMixin):
|
||||
|
||||
def test_zero_copy_turns_off_when_md5_sockets_not_supported(self):
|
||||
if not self._system_can_zero_copy():
|
||||
raise SkipTest("zero-copy support is missing")
|
||||
raise unittest.SkipTest("zero-copy support is missing")
|
||||
df_mgr = self.df_router[POLICIES.default]
|
||||
self.conf['splice'] = 'on'
|
||||
with mock.patch('swift.obj.diskfile.get_md5_socket') as mock_md5sock:
|
||||
@ -4782,8 +4780,7 @@ class DiskFileMixin(BaseDiskFileTestMixin):
|
||||
|
||||
def test_tee_to_md5_pipe_length_mismatch(self):
|
||||
if not self._system_can_zero_copy():
|
||||
raise SkipTest("zero-copy support is missing")
|
||||
|
||||
raise unittest.SkipTest("zero-copy support is missing")
|
||||
self.conf['splice'] = 'on'
|
||||
|
||||
df = self._get_open_disk_file(fsize=16385)
|
||||
@ -4805,8 +4802,7 @@ class DiskFileMixin(BaseDiskFileTestMixin):
|
||||
|
||||
def test_splice_to_wsockfd_blocks(self):
|
||||
if not self._system_can_zero_copy():
|
||||
raise SkipTest("zero-copy support is missing")
|
||||
|
||||
raise unittest.SkipTest("zero-copy support is missing")
|
||||
self.conf['splice'] = 'on'
|
||||
|
||||
df = self._get_open_disk_file(fsize=16385)
|
||||
|
@ -39,8 +39,6 @@ from textwrap import dedent
|
||||
from eventlet import sleep, spawn, wsgi, Timeout, tpool, greenthread
|
||||
from eventlet.green import httplib
|
||||
|
||||
from nose import SkipTest
|
||||
|
||||
from swift import __version__ as swift_version
|
||||
from swift.common.http import is_success
|
||||
from test import listen_zero
|
||||
@ -6408,7 +6406,7 @@ class TestObjectController(unittest.TestCase):
|
||||
except NotImplementedError:
|
||||
# On some operating systems (at a minimum, OS X) it's not possible
|
||||
# to introspect the value of a semaphore
|
||||
raise SkipTest
|
||||
raise unittest.SkipTest
|
||||
else:
|
||||
self.assertEqual(value, 4)
|
||||
|
||||
@ -7636,7 +7634,7 @@ class TestZeroCopy(unittest.TestCase):
|
||||
def setUp(self):
|
||||
skip_if_no_xattrs()
|
||||
if not self._system_can_zero_copy():
|
||||
raise SkipTest("zero-copy support is missing")
|
||||
raise unittest.SkipTest("zero-copy support is missing")
|
||||
|
||||
self.testdir = mkdtemp(suffix="obj_server_zero_copy")
|
||||
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
|
||||
|
Loading…
Reference in New Issue
Block a user