Merge "Remove references to unittest2 library"
This commit is contained in:
commit
a212e07102
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 '
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user