From fc4f45ebdccd87f140f39bebed897053c7f345c5 Mon Sep 17 00:00:00 2001 From: Hasan Ramezani Date: Tue, 4 Feb 2020 21:58:07 +0100 Subject: Used assertRaisesMessage() in various tests. --- tests/fixtures/tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests/fixtures') diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 16e90dea38..0027c62c20 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -541,10 +541,10 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): ]) def test_ambiguous_compressed_fixture(self): - # The name "fixture5" is ambiguous, so loading it will raise an error - with self.assertRaises(management.CommandError) as cm: + # The name "fixture5" is ambiguous, so loading raises an error. + msg = "Multiple fixtures named 'fixture5'" + with self.assertRaisesMessage(management.CommandError, msg): management.call_command('loaddata', 'fixture5', verbosity=0) - self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0]) def test_db_loading(self): # Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly @@ -566,9 +566,9 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): if connection.vendor == 'mysql': with connection.cursor() as cursor: cursor.execute("SET sql_mode = 'TRADITIONAL'") - with self.assertRaises(IntegrityError) as cm: + msg = 'Could not load fixtures.Article(pk=1):' + with self.assertRaisesMessage(IntegrityError, msg): management.call_command('loaddata', 'invalid.json', verbosity=0) - self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0]) @unittest.skipUnless(connection.vendor == 'postgresql', 'psycopg2 prohibits null characters in data.') def test_loaddata_null_characters_on_postgresql(self): @@ -760,9 +760,9 @@ class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): # Try to load fixture 2 using format discovery; this will fail # because there are two fixture2's in the fixtures directory - with self.assertRaises(management.CommandError) as cm: + msg = "Multiple fixtures named 'fixture2'" + with self.assertRaisesMessage(management.CommandError, msg): management.call_command('loaddata', 'fixture2', verbosity=0) - self.assertIn("Multiple fixtures named 'fixture2'", cm.exception.args[0]) # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ -- cgit v1.3