From b541cadef3337fb4cfbc3c1089d59955cca16cab Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 28 Aug 2015 21:20:32 +0100 Subject: [PATCH] Ignore any ResourceWarnings that happen while we're testing for the presence of a deprecation warning --- wagtail/wagtailimages/tests/tests.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/wagtail/wagtailimages/tests/tests.py b/wagtail/wagtailimages/tests/tests.py index d9d5147bd4..978e8d05be 100644 --- a/wagtail/wagtailimages/tests/tests.py +++ b/wagtail/wagtailimages/tests/tests.py @@ -292,13 +292,20 @@ class TestGetImageForm(TestCase, WagtailTestUtils): def test_custom_image_model_without_admin_form_fields_raises_warning(self): self.reset_warning_registry() - with warnings.catch_warnings(record=True) as w: + with warnings.catch_warnings(record=True) as raw_warnings: form = get_image_form(CustomImageWithoutAdminFormFields) # Check that a RemovedInWagtail12Warning has been triggered - self.assertEqual(len(w), 1) - self.assertTrue(issubclass(w[-1].category, RemovedInWagtail12Warning)) - self.assertTrue("Add admin_form_fields = (tuple of field names) to CustomImageWithoutAdminFormFields" in str(w[-1].message)) + + # Ignore any ResourceWarnings. TODO: remove this when we've stopped ResourceWarnings from happening... + try: + clean_warnings = [w for w in raw_warnings if not issubclass(w.category, ResourceWarning)] + except NameError: # ResourceWarning only exists on Python >= 3.2 + clean_warnings = raw_warnings + + self.assertEqual(len(clean_warnings), 1) + self.assertTrue(issubclass(clean_warnings[-1].category, RemovedInWagtail12Warning)) + self.assertTrue("Add admin_form_fields = (tuple of field names) to CustomImageWithoutAdminFormFields" in str(clean_warnings[-1].message)) # All fields, including the not editable one should be on the form self.assertEqual(list(form.base_fields.keys()), [