mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #29363 -- Added SimpleTestCase.assertWarnsMessage().
This commit is contained in:
committed by
Tim Graham
parent
7ba040de77
commit
704443acac
@@ -1,7 +1,7 @@
|
||||
import warnings
|
||||
from datetime import datetime
|
||||
|
||||
from django.test import TestCase
|
||||
from django.utils.deprecation import RemovedInDjango30Warning
|
||||
|
||||
from .models import Article, IndexErrorArticle, Person
|
||||
|
||||
@@ -169,16 +169,12 @@ class EarliestOrLatestTests(TestCase):
|
||||
|
||||
def test_field_name_kwarg_deprecation(self):
|
||||
Person.objects.create(name='Deprecator', birthday=datetime(1950, 1, 1))
|
||||
with warnings.catch_warnings(record=True) as warns:
|
||||
warnings.simplefilter('always')
|
||||
Person.objects.latest(field_name='birthday')
|
||||
|
||||
self.assertEqual(len(warns), 1)
|
||||
self.assertEqual(
|
||||
str(warns[0].message),
|
||||
msg = (
|
||||
'The field_name keyword argument to earliest() and latest() '
|
||||
'is deprecated in favor of passing positional arguments.',
|
||||
'is deprecated in favor of passing positional arguments.'
|
||||
)
|
||||
with self.assertWarnsMessage(RemovedInDjango30Warning, msg):
|
||||
Person.objects.latest(field_name='birthday')
|
||||
|
||||
|
||||
class TestFirstLast(TestCase):
|
||||
|
||||
Reference in New Issue
Block a user