diff options
author | Morgan Aubert <morgan.aubert@impakfinance.com> | 2018-04-27 17:18:15 -0400 |
---|---|---|
committer | Tim Graham <timograham@gmail.com> | 2018-05-09 11:40:28 -0400 |
commit | 704443acacf0dfbcb1c52df4b260585055754ce7 (patch) | |
tree | 600147bf6114d7b490fcd253ff9797b7e7531c09 /tests/fixtures_regress | |
parent | 7ba040de7703fd06b9b35ddd31da40103d911c30 (diff) | |
download | django-704443acacf0dfbcb1c52df4b260585055754ce7.tar.gz |
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
Diffstat (limited to 'tests/fixtures_regress')
-rw-r--r-- | tests/fixtures_regress/tests.py | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py index 3ca5084995..83b007bf59 100644 --- a/tests/fixtures_regress/tests.py +++ b/tests/fixtures_regress/tests.py @@ -2,7 +2,6 @@ import json import os import re -import warnings from io import StringIO from django.core import management, serializers @@ -209,19 +208,13 @@ class TestFixtures(TestCase): using explicit filename. Test for ticket #18213 -- warning conditions are caught correctly """ - with warnings.catch_warnings(record=True) as warning_list: - warnings.simplefilter("always") + msg = "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" + with self.assertWarnsMessage(RuntimeWarning, msg): management.call_command( 'loaddata', 'bad_fixture2.xml', verbosity=0, ) - warning = warning_list.pop() - self.assertEqual(warning.category, RuntimeWarning) - self.assertEqual( - str(warning.message), - "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" - ) def test_invalid_data_no_ext(self): """ @@ -229,55 +222,40 @@ class TestFixtures(TestCase): without file extension. Test for ticket #18213 -- warning conditions are caught correctly """ - with warnings.catch_warnings(record=True) as warning_list: - warnings.simplefilter("always") + msg = "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" + with self.assertWarnsMessage(RuntimeWarning, msg): management.call_command( 'loaddata', 'bad_fixture2', verbosity=0, ) - warning = warning_list.pop() - self.assertEqual(warning.category, RuntimeWarning) - self.assertEqual( - str(warning.message), - "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" - ) def test_empty(self): """ Test for ticket #18213 -- Loading a fixture file with no data output a warning. Previously empty fixture raises an error exception, see ticket #4371. """ - with warnings.catch_warnings(record=True) as warning_list: - warnings.simplefilter("always") + msg = "No fixture data found for 'empty'. (File format may be invalid.)" + with self.assertWarnsMessage(RuntimeWarning, msg): management.call_command( 'loaddata', 'empty', verbosity=0, ) - warning = warning_list.pop() - self.assertEqual(warning.category, RuntimeWarning) - self.assertEqual(str(warning.message), "No fixture data found for 'empty'. (File format may be invalid.)") def test_error_message(self): """ Regression for #9011 - error message is correct. Change from error to warning for ticket #18213. """ - with warnings.catch_warnings(record=True) as warning_list: - warnings.simplefilter("always") + msg = "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" + with self.assertWarnsMessage(RuntimeWarning, msg): management.call_command( 'loaddata', 'bad_fixture2', 'animal', verbosity=0, ) - warning = warning_list.pop() - self.assertEqual(warning.category, RuntimeWarning) - self.assertEqual( - str(warning.message), - "No fixture data found for 'bad_fixture2'. (File format may be invalid.)" - ) def test_pg_sequence_resetting_checks(self): """ |