Removed tests for django.utils.unittest vs. unittest.
Silenced warnings caused by the deprecation of django.utils.unittest. Thanks Preston Timmons and Carl Meyer for their advice. Fixed #20680.
This commit is contained in:
parent
a521d10322
commit
909433fa50
|
@ -12,6 +12,8 @@ from django.db.models import get_app, get_apps
|
||||||
from django.test import _doctest as doctest
|
from django.test import _doctest as doctest
|
||||||
from django.test import runner
|
from django.test import runner
|
||||||
from django.test.utils import compare_xml, strip_quotes
|
from django.test.utils import compare_xml, strip_quotes
|
||||||
|
# django.utils.unittest is deprecated, but so is django.test.simple,
|
||||||
|
# and the latter will be removed before the former.
|
||||||
from django.utils import unittest
|
from django.utils import unittest
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
from django.utils.module_loading import module_has_submodule
|
from django.utils.module_loading import module_has_submodule
|
||||||
|
|
|
@ -377,13 +377,14 @@ class CaptureQueriesContext(object):
|
||||||
|
|
||||||
class IgnoreDeprecationWarningsMixin(object):
|
class IgnoreDeprecationWarningsMixin(object):
|
||||||
|
|
||||||
warning_class = DeprecationWarning
|
warning_classes = [DeprecationWarning]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(IgnoreDeprecationWarningsMixin, self).setUp()
|
super(IgnoreDeprecationWarningsMixin, self).setUp()
|
||||||
self.catch_warnings = warnings.catch_warnings()
|
self.catch_warnings = warnings.catch_warnings()
|
||||||
self.catch_warnings.__enter__()
|
self.catch_warnings.__enter__()
|
||||||
warnings.filterwarnings("ignore", category=self.warning_class)
|
for warning_class in self.warning_classes:
|
||||||
|
warnings.filterwarnings("ignore", category=warning_class)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.catch_warnings.__exit__(*sys.exc_info())
|
self.catch_warnings.__exit__(*sys.exc_info())
|
||||||
|
@ -392,7 +393,12 @@ class IgnoreDeprecationWarningsMixin(object):
|
||||||
|
|
||||||
class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
|
class IgnorePendingDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
|
||||||
|
|
||||||
warning_class = PendingDeprecationWarning
|
warning_classes = [PendingDeprecationWarning]
|
||||||
|
|
||||||
|
|
||||||
|
class IgnoreAllDeprecationWarningsMixin(IgnoreDeprecationWarningsMixin):
|
||||||
|
|
||||||
|
warning_classes = [PendingDeprecationWarning, DeprecationWarning]
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
from unittest import TestCase as UnitTestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from django.test import TestCase as DjangoTestCase
|
from django.test import TestCase as DjangoTestCase
|
||||||
from django.utils.unittest import TestCase as UT2TestCase
|
|
||||||
|
|
||||||
|
|
||||||
class TestVanillaUnittest(UnitTestCase):
|
class TestVanillaUnittest(TestCase):
|
||||||
|
|
||||||
def test_sample(self):
|
|
||||||
self.assertEqual(1, 1)
|
|
||||||
|
|
||||||
|
|
||||||
class TestUnittest2(UT2TestCase):
|
|
||||||
|
|
||||||
def test_sample(self):
|
def test_sample(self):
|
||||||
self.assertEqual(1, 1)
|
self.assertEqual(1, 1)
|
||||||
|
|
|
@ -6,11 +6,6 @@ from unittest import expectedFailure
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.runner import DiscoverRunner
|
from django.test.runner import DiscoverRunner
|
||||||
|
|
||||||
try:
|
|
||||||
import unittest2
|
|
||||||
except ImportError:
|
|
||||||
unittest2 = None
|
|
||||||
|
|
||||||
|
|
||||||
def expectedFailureIf(condition):
|
def expectedFailureIf(condition):
|
||||||
"""Marks a test as an expected failure if ``condition`` is met."""
|
"""Marks a test as an expected failure if ``condition`` is met."""
|
||||||
|
@ -26,7 +21,7 @@ class DiscoverRunnerTest(TestCase):
|
||||||
["test_discovery_sample.tests_sample"],
|
["test_discovery_sample.tests_sample"],
|
||||||
).countTestCases()
|
).countTestCases()
|
||||||
|
|
||||||
self.assertEqual(count, 3)
|
self.assertEqual(count, 2)
|
||||||
|
|
||||||
def test_dotted_test_class_vanilla_unittest(self):
|
def test_dotted_test_class_vanilla_unittest(self):
|
||||||
count = DiscoverRunner().build_suite(
|
count = DiscoverRunner().build_suite(
|
||||||
|
@ -35,13 +30,6 @@ class DiscoverRunnerTest(TestCase):
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
def test_dotted_test_class_unittest2(self):
|
|
||||||
count = DiscoverRunner().build_suite(
|
|
||||||
["test_discovery_sample.tests_sample.TestUnittest2"],
|
|
||||||
).countTestCases()
|
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
|
||||||
|
|
||||||
def test_dotted_test_class_django_testcase(self):
|
def test_dotted_test_class_django_testcase(self):
|
||||||
count = DiscoverRunner().build_suite(
|
count = DiscoverRunner().build_suite(
|
||||||
["test_discovery_sample.tests_sample.TestDjangoTestCase"],
|
["test_discovery_sample.tests_sample.TestDjangoTestCase"],
|
||||||
|
@ -49,23 +37,6 @@ class DiscoverRunnerTest(TestCase):
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
self.assertEqual(count, 1)
|
||||||
|
|
||||||
# this test fails if unittest2 is installed from PyPI on Python 2.6
|
|
||||||
# refs https://code.djangoproject.com/ticket/20437
|
|
||||||
@expectedFailureIf(sys.version_info < (2, 7) and unittest2)
|
|
||||||
def test_dotted_test_method_vanilla_unittest(self):
|
|
||||||
count = DiscoverRunner().build_suite(
|
|
||||||
["test_discovery_sample.tests_sample.TestVanillaUnittest.test_sample"],
|
|
||||||
).countTestCases()
|
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
|
||||||
|
|
||||||
def test_dotted_test_method_unittest2(self):
|
|
||||||
count = DiscoverRunner().build_suite(
|
|
||||||
["test_discovery_sample.tests_sample.TestUnittest2.test_sample"],
|
|
||||||
).countTestCases()
|
|
||||||
|
|
||||||
self.assertEqual(count, 1)
|
|
||||||
|
|
||||||
def test_dotted_test_method_django_testcase(self):
|
def test_dotted_test_method_django_testcase(self):
|
||||||
count = DiscoverRunner().build_suite(
|
count = DiscoverRunner().build_suite(
|
||||||
["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],
|
["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],
|
||||||
|
@ -96,4 +67,4 @@ class DiscoverRunnerTest(TestCase):
|
||||||
["test_discovery_sample/"],
|
["test_discovery_sample/"],
|
||||||
).countTestCases()
|
).countTestCases()
|
||||||
|
|
||||||
self.assertEqual(count, 4)
|
self.assertEqual(count, 3)
|
||||||
|
|
|
@ -12,7 +12,7 @@ from django.core.management import call_command
|
||||||
from django import db
|
from django import db
|
||||||
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
|
from django.test import runner, TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||||
from django.test.testcases import connections_support_transactions
|
from django.test.testcases import connections_support_transactions
|
||||||
from django.test.utils import IgnoreDeprecationWarningsMixin
|
from django.test.utils import IgnoreAllDeprecationWarningsMixin
|
||||||
from django.utils.importlib import import_module
|
from django.utils.importlib import import_module
|
||||||
|
|
||||||
from admin_scripts.tests import AdminScriptTestCase
|
from admin_scripts.tests import AdminScriptTestCase
|
||||||
|
@ -225,7 +225,8 @@ class Ticket17477RegressionTests(AdminScriptTestCase):
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
|
|
||||||
|
|
||||||
class ModulesTestsPackages(IgnoreDeprecationWarningsMixin, unittest.TestCase):
|
class ModulesTestsPackages(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
|
||||||
|
|
||||||
def test_get_tests(self):
|
def test_get_tests(self):
|
||||||
"Check that the get_tests helper function can find tests in a directory"
|
"Check that the get_tests helper function can find tests in a directory"
|
||||||
from django.test.simple import get_tests
|
from django.test.simple import get_tests
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.db.models import get_app
|
from django.db.models import get_app
|
||||||
from django.test.utils import IgnoreDeprecationWarningsMixin
|
from django.test.utils import IgnoreAllDeprecationWarningsMixin
|
||||||
|
|
||||||
|
|
||||||
def suite():
|
def suite():
|
||||||
|
@ -10,7 +10,8 @@ def suite():
|
||||||
return testSuite
|
return testSuite
|
||||||
|
|
||||||
|
|
||||||
class SuiteOverrideTest(IgnoreDeprecationWarningsMixin, unittest.TestCase):
|
class SuiteOverrideTest(IgnoreAllDeprecationWarningsMixin, unittest.TestCase):
|
||||||
|
|
||||||
def test_suite_override(self):
|
def test_suite_override(self):
|
||||||
"""
|
"""
|
||||||
Validate that you can define a custom suite when running tests with
|
Validate that you can define a custom suite when running tests with
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.http import HttpResponse
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
|
||||||
from django.test.html import HTMLParseError, parse_html
|
from django.test.html import HTMLParseError, parse_html
|
||||||
from django.test.utils import CaptureQueriesContext, IgnoreDeprecationWarningsMixin
|
from django.test.utils import CaptureQueriesContext, IgnoreAllDeprecationWarningsMixin
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
from .models import Person
|
from .models import Person
|
||||||
|
@ -592,7 +592,7 @@ class AssertFieldOutputTests(SimpleTestCase):
|
||||||
self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
|
self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
|
||||||
|
|
||||||
|
|
||||||
class DoctestNormalizerTest(IgnoreDeprecationWarningsMixin, SimpleTestCase):
|
class DoctestNormalizerTest(IgnoreAllDeprecationWarningsMixin, SimpleTestCase):
|
||||||
|
|
||||||
def test_normalizer(self):
|
def test_normalizer(self):
|
||||||
from django.test.simple import make_doctest
|
from django.test.simple import make_doctest
|
||||||
|
|
Loading…
Reference in New Issue