Refs #26022 -- Used context manager version of assertRaisesMessage in tests.
Follow up to 253adc2b8a
.
This commit is contained in:
parent
dbe436a9a9
commit
5627057f63
|
@ -89,14 +89,12 @@ class DatesTests(TestCase):
|
||||||
Article.objects.dates()
|
Article.objects.dates()
|
||||||
|
|
||||||
def test_dates_fails_when_given_invalid_field_argument(self):
|
def test_dates_fails_when_given_invalid_field_argument(self):
|
||||||
self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
FieldError,
|
FieldError,
|
||||||
"Cannot resolve keyword 'invalid_field' into field. Choices are: "
|
"Cannot resolve keyword 'invalid_field' into field. Choices are: "
|
||||||
"categories, comments, id, pub_date, pub_datetime, title",
|
"categories, comments, id, pub_date, pub_datetime, title",
|
||||||
Article.objects.dates,
|
):
|
||||||
"invalid_field",
|
Article.objects.dates('invalid_field', 'year')
|
||||||
"year",
|
|
||||||
)
|
|
||||||
|
|
||||||
def test_dates_fails_when_given_invalid_kind_argument(self):
|
def test_dates_fails_when_given_invalid_kind_argument(self):
|
||||||
msg = "'kind' must be one of 'year', 'month', 'week', or 'day'."
|
msg = "'kind' must be one of 'year', 'month', 'week', or 'day'."
|
||||||
|
|
|
@ -34,11 +34,11 @@ class M2MRegressionTests(TestCase):
|
||||||
def test_internal_related_name_not_in_error_msg(self):
|
def test_internal_related_name_not_in_error_msg(self):
|
||||||
# The secret internal related names for self-referential many-to-many
|
# The secret internal related names for self-referential many-to-many
|
||||||
# fields shouldn't appear in the list when an error is made.
|
# fields shouldn't appear in the list when an error is made.
|
||||||
self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
FieldError,
|
FieldError,
|
||||||
"Choices are: id, name, references, related, selfreferchild, selfreferchildsibling",
|
"Choices are: id, name, references, related, selfreferchild, selfreferchildsibling",
|
||||||
lambda: SelfRefer.objects.filter(porcupine='fred')
|
):
|
||||||
)
|
SelfRefer.objects.filter(porcupine='fred')
|
||||||
|
|
||||||
def test_m2m_inheritance_symmetry(self):
|
def test_m2m_inheritance_symmetry(self):
|
||||||
# Test to ensure that the relationship between two inherited models
|
# Test to ensure that the relationship between two inherited models
|
||||||
|
|
|
@ -32,9 +32,11 @@ class SkippingTestCase(SimpleTestCase):
|
||||||
def _assert_skipping(self, func, expected_exc, msg=None):
|
def _assert_skipping(self, func, expected_exc, msg=None):
|
||||||
try:
|
try:
|
||||||
if msg is not None:
|
if msg is not None:
|
||||||
self.assertRaisesMessage(expected_exc, msg, func)
|
with self.assertRaisesMessage(expected_exc, msg):
|
||||||
|
func()
|
||||||
else:
|
else:
|
||||||
self.assertRaises(expected_exc, func)
|
with self.assertRaises(expected_exc):
|
||||||
|
func()
|
||||||
except unittest.SkipTest:
|
except unittest.SkipTest:
|
||||||
self.fail('%s should not result in a skipped test.' % func.__name__)
|
self.fail('%s should not result in a skipped test.' % func.__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue