From 32ca159c96339b4856837d7abec376a575ec44ab Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 30 Dec 2014 02:25:51 +0200 Subject: [PATCH] Ignored warnings correctly in test_get_formsets_with_inlines_returns_tuples(). The subclass check in ModelAdmin.get_formsets_with_inlines() wasn't tested correctly because of the super() call in EpisodeAdmin.get_formsets(). --- django/contrib/admin/options.py | 2 +- tests/generic_inline_admin/tests.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 47c57aa4db..d3f4ad16fc 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -773,7 +773,7 @@ class ModelAdmin(BaseModelAdmin): warnings.warn( "ModelAdmin.get_formsets() is deprecated and will be removed in " "Django 1.9. Use ModelAdmin.get_formsets_with_inlines() instead.", - RemovedInDjango19Warning + RemovedInDjango19Warning, stacklevel=2 ) if formsets: zipped = zip(formsets, self.get_inline_instances(request, None)) diff --git a/tests/generic_inline_admin/tests.py b/tests/generic_inline_admin/tests.py index 3e24168a29..ebc54e082b 100644 --- a/tests/generic_inline_admin/tests.py +++ b/tests/generic_inline_admin/tests.py @@ -9,7 +9,7 @@ from django.contrib.contenttypes.admin import GenericTabularInline from django.contrib.contenttypes.forms import generic_inlineformset_factory from django.forms.formsets import DEFAULT_MAX_NUM from django.forms.models import ModelForm -from django.test import TestCase, override_settings, RequestFactory +from django.test import RequestFactory, TestCase, ignore_warnings, override_settings from django.utils.deprecation import RemovedInDjango19Warning # local test models @@ -474,6 +474,7 @@ class GenericInlineModelAdminTest(TestCase): list(ma.get_formsets_with_inlines(request)) self.assertEqual(len(w), 0) + @ignore_warnings(category=RemovedInDjango19Warning) def test_get_formsets_with_inlines_returns_tuples(self): """ Ensure that get_formsets_with_inlines() returns the correct tuples. @@ -506,14 +507,12 @@ class GenericInlineModelAdminTest(TestCase): ] def get_formsets(self, request, obj=None): - # Catch the deprecation warning to force the usage of get_formsets - with warnings.catch_warnings(record=True): - warnings.simplefilter("always") - return super(EpisodeAdmin, self).get_formsets(request, obj) + # Override get_formsets to force the usage of get_formsets in + # ModelAdmin.get_formsets_with_inlines() then ignore the + # warning raised by ModelAdmin.get_formsets_with_inlines() + return self._get_formsets(request, obj) ma = EpisodeAdmin(Episode, self.site) inlines = ma.get_inline_instances(request) - with warnings.catch_warnings(record=True): - warnings.simplefilter("always") - for (formset, inline), other_inline in zip(ma.get_formsets_with_inlines(request), inlines): - self.assertIsInstance(formset, other_inline.get_formset(request).__class__) + for (formset, inline), other_inline in zip(ma.get_formsets_with_inlines(request), inlines): + self.assertIsInstance(formset, other_inline.get_formset(request).__class__)