Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 36a44ae75f7779b558a60d5d315b36c5e2c98a0c 1 parent 145a77e
@carljm carljm authored
Showing with 18 additions and 1 deletion.
  1. +18 −1 django/contrib/humanize/tests.py
View
19 django/contrib/humanize/tests.py
@@ -159,4 +159,21 @@ def test_naturaltime(self):
'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
Please sign in to comment.
Something went wrong with that request. Please try again.