Mocked datetime in the naturaltime tests to avoid sporadic test failure.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17023 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Carl Meyer 2011-10-22 06:06:44 +00:00
parent 145a77edc9
commit 36a44ae75f
1 changed files with 18 additions and 1 deletions

View File

@ -159,4 +159,21 @@ class HumanizeTests(TestCase):
'1 day from now',
'1 year, 4 months from now',
]
self.humanize_tester(test_list, result_list, 'naturaltime')
# mock out datetime so these tests don't fail occasionally when the
# test runs too slow
class MockDateTime(object):
def now(self):
return now
def __call__(self, *args, **kwargs):
return datetime(*args, **kwargs)
from django.contrib.humanize.templatetags import humanize
orig_datetime = humanize.datetime
humanize.datetime = MockDateTime()
try:
self.humanize_tester(test_list, result_list, 'naturaltime')
finally:
humanize.datetime = orig_datetime