summaryrefslogtreecommitdiff
path: root/tests/test_utils
diff options
context:
space:
mode:
authorMorgan Aubert <morgan.aubert@impakfinance.com>2018-04-27 17:18:15 -0400
committerTim Graham <timograham@gmail.com>2018-05-09 11:40:28 -0400
commit704443acacf0dfbcb1c52df4b260585055754ce7 (patch)
tree600147bf6114d7b490fcd253ff9797b7e7531c09 /tests/test_utils
parent7ba040de7703fd06b9b35ddd31da40103d911c30 (diff)
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
Diffstat (limited to 'tests/test_utils')
-rw-r--r--tests/test_utils/tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index dbb6cd573f..439ca0b7c7 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -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):