Remove usage of unittest2
from comments when it was last touched it looks like workarounds for unittest2 might be able to be dropped. related: https://github.com/mtreinish/stestr/pull/265 simplify the workaround logic around unittest2 TestCase logic Change-Id: Ibac9d0c2fa2f30605dd44ee58b84946464ea6449
This commit is contained in:
parent
eb860bca57
commit
1ff7748623
@ -21,4 +21,3 @@ stevedore>=1.20.0 # Apache-2.0
|
|||||||
PrettyTable>=0.7.1 # BSD
|
PrettyTable>=0.7.1 # BSD
|
||||||
urllib3>=1.21.1 # MIT
|
urllib3>=1.21.1 # MIT
|
||||||
debtcollector>=1.2.0 # Apache-2.0
|
debtcollector>=1.2.0 # Apache-2.0
|
||||||
unittest2>=1.1.0 # BSD
|
|
||||||
|
@ -14,29 +14,11 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
import pkg_resources
|
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
|
|
||||||
def _handle_skip_exception():
|
|
||||||
try:
|
|
||||||
stestr_version = pkg_resources.parse_version(
|
|
||||||
pkg_resources.get_distribution("stestr").version)
|
|
||||||
stestr_min = pkg_resources.parse_version('2.5.0')
|
|
||||||
new_stestr = (stestr_version >= stestr_min)
|
|
||||||
import unittest
|
|
||||||
import unittest2
|
|
||||||
if sys.version_info >= (3, 5) and new_stestr:
|
|
||||||
testtools.TestCase.skipException = unittest.case.SkipTest
|
|
||||||
else:
|
|
||||||
testtools.TestCase.skipException = unittest2.case.SkipTest
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase):
|
class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase):
|
||||||
setUpClassCalled = False
|
setUpClassCalled = False
|
||||||
|
|
||||||
@ -51,18 +33,6 @@ class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase):
|
|||||||
if hasattr(super(BaseTestCase, cls), 'setUpClass'):
|
if hasattr(super(BaseTestCase, cls), 'setUpClass'):
|
||||||
super(BaseTestCase, cls).setUpClass()
|
super(BaseTestCase, cls).setUpClass()
|
||||||
cls.setUpClassCalled = True
|
cls.setUpClassCalled = True
|
||||||
# TODO(gmann): cls.handle_skip_exception is really workaround for
|
|
||||||
# testtools bug- https://github.com/testing-cabal/testtools/issues/272
|
|
||||||
# stestr which is used by Tempest internally to run the test switch
|
|
||||||
# the customize test runner(which use stdlib unittest) for >=py3.5
|
|
||||||
# else testtools.run.- https://github.com/mtreinish/stestr/pull/265
|
|
||||||
# These two test runner are not compatible due to skip exception
|
|
||||||
# handling(due to unittest2). testtools.run treat unittestt.SkipTest
|
|
||||||
# as error and stdlib unittest treat unittest2.case.SkipTest raised
|
|
||||||
# by testtools.TestCase.skipException.
|
|
||||||
# The below workaround can be removed once testtools fix issue# 272.
|
|
||||||
cls.orig_skip_exception = testtools.TestCase.skipException
|
|
||||||
_handle_skip_exception()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
@ -70,7 +40,6 @@ class BaseTestCase(testtools.testcase.WithAttributes, testtools.TestCase):
|
|||||||
super(BaseTestCase, cls).tearDownClass()
|
super(BaseTestCase, cls).tearDownClass()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
testtools.TestCase.skipException = self.orig_skip_exception
|
|
||||||
super(BaseTestCase, self).setUp()
|
super(BaseTestCase, self).setUp()
|
||||||
if not self.setUpClassCalled:
|
if not self.setUpClassCalled:
|
||||||
raise RuntimeError("setUpClass does not calls the super's "
|
raise RuntimeError("setUpClass does not calls the super's "
|
||||||
|
@ -26,7 +26,6 @@ from tempest import clients
|
|||||||
from tempest.common import credentials_factory as credentials
|
from tempest.common import credentials_factory as credentials
|
||||||
from tempest.common import utils
|
from tempest.common import utils
|
||||||
from tempest import config
|
from tempest import config
|
||||||
from tempest.lib import base as lib_base
|
|
||||||
from tempest.lib.common import api_microversion_fixture
|
from tempest.lib.common import api_microversion_fixture
|
||||||
from tempest.lib.common import fixed_network
|
from tempest.lib.common import fixed_network
|
||||||
from tempest.lib.common import profiler
|
from tempest.lib.common import profiler
|
||||||
@ -142,19 +141,6 @@ class BaseTestCase(testtools.testcase.WithAttributes,
|
|||||||
# It should never be overridden by descendants
|
# It should never be overridden by descendants
|
||||||
if hasattr(super(BaseTestCase, cls), 'setUpClass'):
|
if hasattr(super(BaseTestCase, cls), 'setUpClass'):
|
||||||
super(BaseTestCase, cls).setUpClass()
|
super(BaseTestCase, cls).setUpClass()
|
||||||
# All the configuration checks that may generate a skip
|
|
||||||
# TODO(gmann): cls.handle_skip_exception is really workaround for
|
|
||||||
# testtools bug- https://github.com/testing-cabal/testtools/issues/272
|
|
||||||
# stestr which is used by Tempest internally to run the test switch
|
|
||||||
# the customize test runner(which use stdlib unittest) for >=py3.5
|
|
||||||
# else testtools.run.- https://github.com/mtreinish/stestr/pull/265
|
|
||||||
# These two test runner are not compatible due to skip exception
|
|
||||||
# handling(due to unittest2). testtools.run treat unittestt.SkipTest
|
|
||||||
# as error and stdlib unittest treat unittest2.case.SkipTest raised
|
|
||||||
# by testtools.TestCase.skipException.
|
|
||||||
# The below workaround can be removed once testtools fix issue# 272.
|
|
||||||
orig_skip_exception = testtools.TestCase.skipException
|
|
||||||
lib_base._handle_skip_exception()
|
|
||||||
try:
|
try:
|
||||||
cls.skip_checks()
|
cls.skip_checks()
|
||||||
|
|
||||||
@ -182,8 +168,6 @@ class BaseTestCase(testtools.testcase.WithAttributes,
|
|||||||
raise value.with_traceback(trace)
|
raise value.with_traceback(trace)
|
||||||
finally:
|
finally:
|
||||||
del trace # to avoid circular refs
|
del trace # to avoid circular refs
|
||||||
finally:
|
|
||||||
testtools.TestCase.skipException = orig_skip_exception
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tearDownClass(cls):
|
def tearDownClass(cls):
|
||||||
|
@ -13,15 +13,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import unittest
|
||||||
|
|
||||||
from tempest.test_discover import plugins
|
from tempest.test_discover import plugins
|
||||||
|
|
||||||
if sys.version_info >= (2, 7):
|
|
||||||
import unittest
|
|
||||||
else:
|
|
||||||
import unittest2 as unittest
|
|
||||||
|
|
||||||
|
|
||||||
def load_tests(loader, tests, pattern):
|
def load_tests(loader, tests, pattern):
|
||||||
ext_plugins = plugins.TempestTestPluginManager()
|
ext_plugins = plugins.TempestTestPluginManager()
|
||||||
|
@ -48,7 +48,7 @@ class TestSetUpClass(base.BaseTestCase):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls): # noqa
|
def setUpClass(cls): # noqa
|
||||||
"""Simulate absence of super() call."""
|
"""Simulate absence of super() call."""
|
||||||
cls.orig_skip_exception = cls.skipException
|
pass
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
try:
|
try:
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import unittest
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
@ -34,12 +34,6 @@ from tempest.tests.lib import fake_credentials
|
|||||||
from tempest.tests.lib.services import registry_fixture
|
from tempest.tests.lib.services import registry_fixture
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info >= (2, 7):
|
|
||||||
import unittest
|
|
||||||
else:
|
|
||||||
import unittest2 as unittest
|
|
||||||
|
|
||||||
|
|
||||||
class LoggingTestResult(testtools.TestResult):
|
class LoggingTestResult(testtools.TestResult):
|
||||||
|
|
||||||
def __init__(self, log, *args, **kwargs):
|
def __init__(self, log, *args, **kwargs):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user