diff options
| author | Carl Meyer <carl@oddbird.net> | 2011-10-22 06:06:44 +0000 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2011-10-22 06:06:44 +0000 |
| commit | 36a44ae75f7779b558a60d5d315b36c5e2c98a0c (patch) | |
| tree | ad0e9f6b4910591c8d1509790593e84bce6b5adc | |
| parent | 145a77edc999fd5f1a53bc5bfd6b581386950074 (diff) | |
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
| -rw-r--r-- | django/contrib/humanize/tests.py | 19 |
1 files changed, 18 insertions, 1 deletions
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 |
