From 46789e76c68b5713795fbf71ce5fdccb727074fa Mon Sep 17 00:00:00 2001 From: Marc Tamlyn Date: Fri, 14 Jun 2013 15:02:30 +0100 Subject: [PATCH] Fixed #20548 -- Removed all PendingDeprecationWarnings from django test suite --- tests/forms_tests/tests/tests.py | 6 ++++-- tests/model_forms/tests.py | 5 ++++- tests/model_forms_regress/tests.py | 4 +++- tests/runtests.py | 5 ++++- tests/test_runner/tests.py | 14 ++++++++------ tests/test_suite_override/tests.py | 5 +++-- tests/test_utils/tests.py | 6 +++--- 7 files changed, 29 insertions(+), 16 deletions(-) diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index 2616ddaf7d0..99a67c320c5 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -208,7 +208,8 @@ class RelatedModelFormTests(TestCase): ref = models.ForeignKey("B") class Meta: - model=A + model = A + fields = '__all__' self.assertRaises(ValueError, ModelFormMetaclass, str('Form'), (ModelForm,), {'Meta': Meta}) @@ -226,7 +227,8 @@ class RelatedModelFormTests(TestCase): pass class Meta: - model=A + model = A + fields = '__all__' self.assertTrue(issubclass(ModelFormMetaclass(str('Form'), (ModelForm,), {'Meta': Meta}), ModelForm)) diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index aadc7a618e0..eea1ef9b686 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -52,12 +52,15 @@ class PriceForm(forms.ModelForm): class BookForm(forms.ModelForm): class Meta: - model = Book + model = Book + fields = '__all__' class DerivedBookForm(forms.ModelForm): class Meta: model = DerivedBook + fields = '__all__' + class ExplicitPKForm(forms.ModelForm): diff --git a/tests/model_forms_regress/tests.py b/tests/model_forms_regress/tests.py index 80900a59e0f..39ae8572192 100644 --- a/tests/model_forms_regress/tests.py +++ b/tests/model_forms_regress/tests.py @@ -97,12 +97,14 @@ class PartiallyLocalizedTripleForm(forms.ModelForm): class Meta: model = Triple localized_fields = ('left', 'right',) + fields = '__all__' class FullyLocalizedTripleForm(forms.ModelForm): class Meta: model = Triple - localized_fields = "__all__" + localized_fields = '__all__' + fields = '__all__' class LocalizedModelFormTest(TestCase): def test_model_form_applies_localize_to_some_fields(self): diff --git a/tests/runtests.py b/tests/runtests.py index 24144103759..da4592ecc08 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys import tempfile +import warnings from django import contrib from django.utils._os import upath @@ -107,7 +108,9 @@ def setup(verbosity, test_labels): logger.addHandler(handler) # Load all the ALWAYS_INSTALLED_APPS. - get_apps() + with warnings.catch_warnings(): + warnings.filterwarnings('ignore', 'django.contrib.comments is deprecated and will be removed before Django 1.8.', PendingDeprecationWarning) + get_apps() # Load all the test model apps. test_modules = get_test_modules() diff --git a/tests/test_runner/tests.py b/tests/test_runner/tests.py index 74a557af26e..03a3619c7e4 100644 --- a/tests/test_runner/tests.py +++ b/tests/test_runner/tests.py @@ -10,8 +10,8 @@ from django.core.exceptions import ImproperlyConfigured from django.core.management import call_command from django import db from django.test import runner, TransactionTestCase, skipUnlessDBFeature -from django.test.simple import DjangoTestSuiteRunner, get_tests from django.test.testcases import connections_support_transactions +from django.test.utils import IgnorePendingDeprecationWarningsMixin from django.utils import unittest from django.utils.importlib import import_module @@ -225,15 +225,17 @@ class Ticket17477RegressionTests(AdminScriptTestCase): self.assertNoOutput(err) -class ModulesTestsPackages(unittest.TestCase): +class ModulesTestsPackages(IgnorePendingDeprecationWarningsMixin, unittest.TestCase): def test_get_tests(self): "Check that the get_tests helper function can find tests in a directory" + from django.test.simple import get_tests module = import_module(TEST_APP_OK) tests = get_tests(module) self.assertIsInstance(tests, type(module)) def test_import_error(self): "Test for #12658 - Tests with ImportError's shouldn't fail silently" + from django.test.simple import get_tests module = import_module(TEST_APP_ERROR) self.assertRaises(ImportError, get_tests, module) @@ -258,7 +260,7 @@ class Sqlite3InMemoryTestDbs(unittest.TestCase): }, }) other = db.connections['other'] - DjangoTestSuiteRunner(verbosity=0).setup_databases() + runner.DiscoverRunner(verbosity=0).setup_databases() msg = "DATABASES setting '%s' option set to sqlite3's ':memory:' value shouldn't interfere with transaction support detection." % option # Transaction support should be properly initialised for the 'other' DB self.assertTrue(other.features.supports_transactions, msg) @@ -273,12 +275,12 @@ class DummyBackendTest(unittest.TestCase): """ Test that setup_databases() doesn't fail with dummy database backend. """ - runner = DjangoTestSuiteRunner(verbosity=0) + runner_instance = runner.DiscoverRunner(verbosity=0) old_db_connections = db.connections try: db.connections = db.ConnectionHandler({}) - old_config = runner.setup_databases() - runner.teardown_databases(old_config) + old_config = runner_instance.setup_databases() + runner_instance.teardown_databases(old_config) except Exception as e: self.fail("setup_databases/teardown_databases unexpectedly raised " "an error: %s" % e) diff --git a/tests/test_suite_override/tests.py b/tests/test_suite_override/tests.py index dea110434f9..35ca2b060b0 100644 --- a/tests/test_suite_override/tests.py +++ b/tests/test_suite_override/tests.py @@ -1,5 +1,5 @@ from django.db.models import get_app -from django.test.simple import build_suite +from django.test.utils import IgnorePendingDeprecationWarningsMixin from django.utils import unittest @@ -9,7 +9,7 @@ def suite(): return testSuite -class SuiteOverrideTest(unittest.TestCase): +class SuiteOverrideTest(IgnorePendingDeprecationWarningsMixin, unittest.TestCase): def test_suite_override(self): """ Validate that you can define a custom suite when running tests with @@ -17,6 +17,7 @@ class SuiteOverrideTest(unittest.TestCase): suite using ``build_suite``). """ + from django.test.simple import build_suite app = get_app("test_suite_override") suite = build_suite(app) self.assertEqual(suite.countTestCases(), 1) diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py index d72a4828194..5f7fb05eb48 100644 --- a/tests/test_utils/tests.py +++ b/tests/test_utils/tests.py @@ -8,8 +8,7 @@ from django.http import HttpResponse from django.template.loader import render_to_string from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test.html import HTMLParseError, parse_html -from django.test.simple import make_doctest -from django.test.utils import CaptureQueriesContext +from django.test.utils import CaptureQueriesContext, IgnorePendingDeprecationWarningsMixin from django.utils import six from django.utils import unittest from django.utils.unittest import skip @@ -624,9 +623,10 @@ class AssertFieldOutputTests(SimpleTestCase): self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None) -class DoctestNormalizerTest(SimpleTestCase): +class DoctestNormalizerTest(IgnorePendingDeprecationWarningsMixin, SimpleTestCase): def test_normalizer(self): + from django.test.simple import make_doctest suite = make_doctest("test_utils.doctest_output") failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite) self.assertEqual(failures.failures, [])