mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
This commit is contained in:
parent
7ba040de77
commit
704443acac
21 changed files with 210 additions and 285 deletions
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import unittest
|
||||
import warnings
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
|
||||
|
@ -864,6 +865,30 @@ class AssertRaisesMsgTest(SimpleTestCase):
|
|||
func1()
|
||||
|
||||
|
||||
class AssertWarnsMessageTests(SimpleTestCase):
|
||||
|
||||
def test_context_manager(self):
|
||||
with self.assertWarnsMessage(UserWarning, 'Expected message'):
|
||||
warnings.warn('Expected message', UserWarning)
|
||||
|
||||
def test_context_manager_failure(self):
|
||||
msg = "Expected message' not found in 'Unexpected message'"
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
with self.assertWarnsMessage(UserWarning, 'Expected message'):
|
||||
warnings.warn('Unexpected message', UserWarning)
|
||||
|
||||
def test_callable(self):
|
||||
def func():
|
||||
warnings.warn('Expected message', UserWarning)
|
||||
self.assertWarnsMessage(UserWarning, 'Expected message', func)
|
||||
|
||||
def test_special_re_chars(self):
|
||||
def func1():
|
||||
warnings.warn('[.*x+]y?', UserWarning)
|
||||
with self.assertWarnsMessage(UserWarning, '[.*x+]y?'):
|
||||
func1()
|
||||
|
||||
|
||||
class AssertFieldOutputTests(SimpleTestCase):
|
||||
|
||||
def test_assert_field_output(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue