#37072: assertWarnsMessage() also ignores entire warning category
-------------------------------------+-------------------------------------
Reporter: Mike Edmunds | Owner: Artyom
| Kotovskiy
Type: Bug | Status: assigned
Component: Testing framework | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Artyom Kotovskiy):
Replying to [comment:5 Mike Edmunds]:
> Python unittest's `assertWarnsRegex()` has the same (problematic)
behavior: https://github.com/python/cpython/issues/143231. And a comment
in that issue proposes a similar fix to the one I described above for
Django's `assertWarnsMessage()`.
>
> In some local experimentation, there are a handful of existing Django
tests that unintentionally depend on the current behavior and would need
to be updated (e.g., by adding appropriate `ignore_warnings()` for the
non-matching deprecation messages those tests don't care about).
>
> There also seem to be a handful of existing Django tests that
''intentionally'' depend on `assertWarnsMessage()` capturing ''multiple''
instances of the same message. (So the answer to my question in
`test_duplicate_warnings_should_maybe_also_error()` above is: duplicate
warnings should ''not'' error, at least not by default.)
>
Am I missing something or those #37072 and #37076 are kind of
contradicting each other?
We expect this to pass
{{{
def test_deprecated_in_my_app(self):
with self.assertWarnsMessage(DeprecationWarning, "Deprecated in
MyApp"):
warnings.warn("Deprecated in Django",
RemovedInNextVersionWarning)
warnings.warn("Deprecated in MyApp", DeprecationWarning)
}}}
And this to fail.
def test_so_this_should_also_error_but_does_not(self):
with self.assertWarnsMessage(RemovedInDjango70Warning, "Expected
deprecation"):
warnings.warn("Expected deprecation",
RemovedInDjango70Warning)
warnings.warn("Unrelated deprecation",
RemovedInDjango70Warning)
RemovedInNextVersionWarning is a subclass of DeprecationWarning. So as I
see it they both have same category, different message — but one should
pass and one should fail.
--
Ticket URL: <https://code.djangoproject.com/ticket/37072#comment:7>
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/0107019de221478a-db4f9304-18da-49fe-a7e7-cbaaecec58e5-000000%40eu-central-1.amazonses.com.