summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HACKING.rst5
-rw-r--r--lower-constraints.txt1
-rw-r--r--neutron/hacking/checks.py15
-rw-r--r--neutron/tests/common/base.py5
-rw-r--r--neutron/tests/functional/pecan_wsgi/__init__.py4
-rw-r--r--neutron/tests/tools.py4
-rw-r--r--neutron/tests/unit/hacking/test_checks.py12
-rw-r--r--neutron/tests/unit/tests/test_base.py4
8 files changed, 9 insertions, 41 deletions
diff --git a/HACKING.rst b/HACKING.rst
index 0036a99c6c..19b0098170 100644
--- a/HACKING.rst
+++ b/HACKING.rst
@@ -21,7 +21,6 @@ Below you can find a list of checks specific to this repository.
- [N331] Detect wrong usage with assertTrue(isinstance()).
- [N332] Use assertEqual(expected_http_code, observed_http_code) instead of
assertEqual(observed_http_code, expected_http_code).
-- [N334] Use unittest2 uniformly across Neutron.
- [N340] Check usage of <module>.i18n (and neutron.i18n)
- [N341] Check usage of _ from python builtins
- [N343] Production code must not import from neutron.tests.*
@@ -46,9 +45,7 @@ without the patch and passes with the patch.
All unittest classes must ultimately inherit from testtools.TestCase. In the
Neutron test suite, this should be done by inheriting from
-neutron.tests.base.BaseTestCase. If the third party unittest library has to
-be used directly then it is recommended to use unittest2 as it contains bug
-fixes to unittest for all versions of Python prior to version 3.5.
+neutron.tests.base.BaseTestCase.
All setUp and tearDown methods must upcall using the super() method.
tearDown methods should be avoided and addCleanup calls should be preferred.
diff --git a/lower-constraints.txt b/lower-constraints.txt
index ac9daf9bb6..85042b5d6a 100644
--- a/lower-constraints.txt
+++ b/lower-constraints.txt
@@ -146,7 +146,6 @@ testtools==2.2.0
tooz==1.58.0
tinyrpc==0.6
traceback2==1.4.0
-unittest2==1.1.0
vine==1.1.4
waitress==1.1.0
WebOb==1.8.2
diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py
index f7b23d89ec..b11c0aae9b 100644
--- a/neutron/hacking/checks.py
+++ b/neutron/hacking/checks.py
@@ -15,7 +15,6 @@
import os
import re
-from hacking import core
from neutron_lib.hacking import checks
@@ -42,8 +41,6 @@ def flake8ext(f):
# neutron/tests/unit/hacking/test_checks.py
-unittest_imports_dot = re.compile(r"\bimport[\s]+unittest\b")
-unittest_imports_from = re.compile(r"\bfrom[\s]+unittest\b")
filter_match = re.compile(r".*filter\(lambda ")
tests_imports_dot = re.compile(r"\bimport[\s]+neutron.tests\b")
@@ -204,17 +201,6 @@ def check_builtins_gettext(logical_line, tokens, filename, lines, noqa):
yield (0, msg)
-@core.flake8ext
-@core.off_by_default
-def check_unittest_imports(logical_line):
- """N334 - Use unittest2 instead of unittest"""
- if (re.match(unittest_imports_from, logical_line) or
- re.match(unittest_imports_dot, logical_line)):
- msg = "N334: '%s' must be used instead of '%s'." % (
- logical_line.replace('unittest', 'unittest2'), logical_line)
- yield (0, msg)
-
-
@flake8ext
def check_no_imports_from_tests(logical_line, filename, noqa):
"""N343 Production code must not import from neutron.tests.*
@@ -270,7 +256,6 @@ def factory(register):
register(check_assertequal_for_httpcode)
register(check_oslo_i18n_wrapper)
register(check_builtins_gettext)
- register(check_unittest_imports)
register(check_no_imports_from_tests)
register(check_python3_no_filter)
register(check_no_sqlalchemy_event_import)
diff --git a/neutron/tests/common/base.py b/neutron/tests/common/base.py
index bad6db17ce..597d71dd0a 100644
--- a/neutron/tests/common/base.py
+++ b/neutron/tests/common/base.py
@@ -12,10 +12,10 @@
#
import functools
+import unittest
from neutron_lib import constants as n_const
import testtools.testcase
-import unittest2.case
from neutron.common import utils
from neutron.tests import base
@@ -61,8 +61,7 @@ def no_skip_on_missing_deps(wrapped):
def wrapper(*args, **kwargs):
try:
return wrapped(*args, **kwargs)
- except (testtools.TestCase.skipException,
- unittest2.case.SkipTest) as e:
+ except (testtools.TestCase.skipException, unittest.SkipTest) as e:
if base.bool_from_env('OS_FAIL_ON_MISSING_DEPS'):
tools.fail(
'%s cannot be skipped because OS_FAIL_ON_MISSING_DEPS '
diff --git a/neutron/tests/functional/pecan_wsgi/__init__.py b/neutron/tests/functional/pecan_wsgi/__init__.py
index 3ddd20d8c4..ce82525329 100644
--- a/neutron/tests/functional/pecan_wsgi/__init__.py
+++ b/neutron/tests/functional/pecan_wsgi/__init__.py
@@ -15,16 +15,16 @@
import os
+import unittest
from pecan import set_config
from pecan.testing import load_test_app
-import unittest2
__all__ = ['FunctionalTest']
-class FunctionalTest(unittest2.TestCase):
+class FunctionalTest(unittest.TestCase):
"""Pecan wsgi functional test base class
Used for functional tests where you need to test your
diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py
index 9e292b392e..069fadf9c8 100644
--- a/neutron/tests/tools.py
+++ b/neutron/tests/tools.py
@@ -15,6 +15,7 @@
import datetime
import random
+import unittest
import fixtures
import netaddr
@@ -24,7 +25,6 @@ from neutron_lib.utils import helpers
from neutron_lib.utils import net
from oslo_utils import netutils
from oslo_utils import timeutils
-import unittest2
# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added and
@@ -159,7 +159,7 @@ def fail(msg=None):
This method is equivalent to TestCase.fail without requiring a
testcase instance (usefully for reducing coupling).
"""
- raise unittest2.TestCase.failureException(msg)
+ raise unittest.TestCase.failureException(msg)
def get_random_string_list(i=3, n=5):
diff --git a/neutron/tests/unit/hacking/test_checks.py b/neutron/tests/unit/hacking/test_checks.py
index 270546eddc..43f75c201c 100644
--- a/neutron/tests/unit/hacking/test_checks.py
+++ b/neutron/tests/unit/hacking/test_checks.py
@@ -195,18 +195,6 @@ class HackingTestCase(base.BaseTestCase):
0, len(list(checks.check_assertequal_for_httpcode(pass_code,
"neutron/tests/test_assert.py"))))
- def test_unittest_imports(self):
- f = checks.check_unittest_imports
-
- self.assertLinePasses(f, 'from unittest2')
- self.assertLinePasses(f, 'import unittest2')
- self.assertLinePasses(f, 'from unitest2 import case')
- self.assertLinePasses(f, 'unittest2.TestSuite')
-
- self.assertLineFails(f, 'from unittest import case')
- self.assertLineFails(f, 'from unittest.TestSuite')
- self.assertLineFails(f, 'import unittest')
-
def test_check_no_imports_from_tests(self):
fail_codes = ('from neutron import tests',
'from neutron.tests import base',
diff --git a/neutron/tests/unit/tests/test_base.py b/neutron/tests/unit/tests/test_base.py
index 0c844ef710..595017e7d6 100644
--- a/neutron/tests/unit/tests/test_base.py
+++ b/neutron/tests/unit/tests/test_base.py
@@ -16,9 +16,9 @@
"""Tests to test the test framework"""
import sys
+import unittest
import eventlet.timeout
-import unittest2
from neutron.tests import base
@@ -62,7 +62,7 @@ class SystemExitTestCase(base.DietTestCase):
def test_sysexit(self):
expectedFails = [self.MyTestCase(exitcode) for exitcode in (0, 1)]
- suite = unittest2.TestSuite(tests=expectedFails)
+ suite = unittest.TestSuite(tests=expectedFails)
result = self.defaultTestResult()
try:
suite.run(result)