#18608: Broken monkey-patching in humanize tests --------------------------------------------+------------------------ Reporter: aaugustin | Owner: nobody Type: Bug | Status: new Component: contrib.humanize | Version: 1.4 Severity: Normal | Keywords: Triage Stage: Unreviewed | Has patch: 0 Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | --------------------------------------------+------------------------ The tests for `django.contrib.humanize` monkey-patch the `datetime` module in `django.utils.timesince` as follows: {{{ timesince.datetime = new.module(b"mock_datetime") timesince.datetime.datetime = MockDateTime }}}
Unfortunately, this means that `isinstance(d, datetime.datetime)` in `django.utils.timesince` will return `False` while the monkey-patch is in effect even though `d` is a real `datetime.datetime`. The `humanize` tests rely on a fixed value: `now = datetime.datetime(2012, 3, 9)` which happens to be at 0h00. They pass by accident, really. Add an hour and a minute to `now` — this shouldn't matter at all — and they'll fail! This is preventing me from writing correct tests for #18504, because `datetime` objects are treated as `date` objects and their time part is ignored. It's impossible to write tests for edge cases around DST changes with this bug. I hope I don't need to explain how horrible this was to debug :( -- Ticket URL: <https://code.djangoproject.com/ticket/18608> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.