#37072: assertWarnsMessage() also ignores entire warning category
-------------------------------------+-------------------------------------
     Reporter:  Mike Edmunds         |                     Type:  Bug
       Status:  new                  |                Component:  Testing
                                     |  framework
      Version:  6.0                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 `assertWarnsMessage(category, message)` implicitly does the equivalent of
 `ignore_warnings(category)`. As a result, tests for particular deprecation
 warnings can overlook other, unrelated deprecation warnings coming from
 the code being tested.

 You would expect the second test case below to cause an error for
 `RemovedInDjango70Warning: Unrelated deprecation`, but it actually passes:

 {{{#!python
 class SomeTests(SimpleTestCase):
     def test_this_errors_as_expected(self):
         # ERROR: RemovedInDjango70Warning: Unrelated deprecation
         warnings.warn("Unrelated deprecation", RemovedInDjango70Warning)

     def test_so_this_should_also_error_but_does_not(self):
         with self.assertWarnsMessage(RemovedInDjango70Warning, "Expected
 deprecation"):
             warnings.warn("Expected deprecation",
 RemovedInDjango70Warning)
             # This gets ignored.
             warnings.warn("Unrelated deprecation",
 RemovedInDjango70Warning)

     def test_duplicate_warnings_should_maybe_also_error(self):
         with self.assertWarnsMessage(RemovedInDjango70Warning, "Expected
 deprecation"):
             warnings.warn("Expected deprecation",
 RemovedInDjango70Warning)
             # This also gets ignored. Maybe it shouldn't?
             warnings.warn("Expected deprecation",
 RemovedInDjango70Warning)
 }}}

 The problem is `assertWarnsMessage()` and `assertRaisesMessage()` try to
 share `SimpleTestCase._assertFooMessage()`, which wraps `assertWarns()`
 and `assertRaises()` respectively. But those methods aren't really
 parallel: there can be only one error raised, but execution can continue
 after a warning. `assertWarns(category)` captures ''all'' warnings in the
 category.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/37072>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019dd0d725e4-ffb2c432-8fe9-4892-b572-3a80dc69be7b-000000%40eu-central-1.amazonses.com.

Reply via email to