diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2020-02-04 21:58:07 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-02-07 12:46:23 +0100 |
| commit | fc4f45ebdccd87f140f39bebed897053c7f345c5 (patch) | |
| tree | 0080670fe0c04124b7b2e15766fac2d73a00f164 /tests/fixtures | |
| parent | 71756bdfed5029bd14dce8cb3c5629efc4be55ac (diff) | |
Used assertRaisesMessage() in various tests.
Diffstat (limited to 'tests/fixtures')
| -rw-r--r-- | tests/fixtures/tests.py | 14 |
1 files changed, 7 insertions, 7 deletions
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(), [ |
