From 3d0dcd7f5af378d3ab6adb303b913e6c7b2e0ee5 Mon Sep 17 00:00:00 2001 From: Hasan Date: Sun, 17 Jan 2016 14:56:39 +0330 Subject: Refs #26022 -- Used context manager version of assertRaises in tests. --- tests/many_to_one_null/tests.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/many_to_one_null') diff --git a/tests/many_to_one_null/tests.py b/tests/many_to_one_null/tests.py index 91c2e13cd7..1a3785bd33 100644 --- a/tests/many_to_one_null/tests.py +++ b/tests/many_to_one_null/tests.py @@ -44,7 +44,8 @@ class ManyToOneNullTests(TestCase): self.assertEqual(self.a3.reporter, None) # Need to reget a3 to refresh the cache a3 = Article.objects.get(pk=self.a3.pk) - self.assertRaises(AttributeError, getattr, a3.reporter, 'id') + with self.assertRaises(AttributeError): + getattr(a3.reporter, 'id') # Accessing an article's 'reporter' attribute returns None # if the reporter is set to None. self.assertEqual(a3.reporter, None) @@ -71,7 +72,8 @@ class ManyToOneNullTests(TestCase): def test_remove_from_wrong_set(self): self.assertQuerysetEqual(self.r2.article_set.all(), ['']) # Try to remove a4 from a set it does not belong to - self.assertRaises(Reporter.DoesNotExist, self.r.article_set.remove, self.a4) + with self.assertRaises(Reporter.DoesNotExist): + self.r.article_set.remove(self.a4) self.assertQuerysetEqual(self.r2.article_set.all(), ['']) def test_set(self): -- cgit v1.2.1