mirror of
https://github.com/django/django.git
synced 2025-08-04 19:08:28 +00:00
Refs #26022 -- Used context manager version of assertRaises in tests.
This commit is contained in:
parent
575706331b
commit
3d0dcd7f5a
118 changed files with 1086 additions and 760 deletions
|
@ -131,10 +131,8 @@ class BasicCustomPKTests(TestCase):
|
|||
self.assertEqual(Employee.objects.get(pk=123), self.dan)
|
||||
self.assertEqual(Employee.objects.get(pk=456), self.fran)
|
||||
|
||||
self.assertRaises(
|
||||
Employee.DoesNotExist,
|
||||
lambda: Employee.objects.get(pk=42)
|
||||
)
|
||||
with self.assertRaises(Employee.DoesNotExist):
|
||||
Employee.objects.get(pk=42)
|
||||
|
||||
# Use the name of the primary key, rather than pk.
|
||||
self.assertEqual(Employee.objects.get(employee_code=123), self.dan)
|
||||
|
@ -151,7 +149,8 @@ class BasicCustomPKTests(TestCase):
|
|||
# Or we can use the real attribute name for the primary key:
|
||||
self.assertEqual(e.employee_code, 123)
|
||||
|
||||
self.assertRaises(AttributeError, lambda: e.id)
|
||||
with self.assertRaises(AttributeError):
|
||||
e.id
|
||||
|
||||
def test_in_bulk(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue