From 36a44ae75f7779b558a60d5d315b36c5e2c98a0c Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Sat, 22 Oct 2011 06:06:44 +0000 Subject: [PATCH] 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 --- django/contrib/humanize/tests.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/django/contrib/humanize/tests.py b/django/contrib/humanize/tests.py index 611314881f..17fa2bf3bb 100644 --- a/django/contrib/humanize/tests.py +++ b/django/contrib/humanize/tests.py @@ -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