Change in iso8601 0.1.12 parse_date() breaks unit test

Bug #1747575 reported by John L. Villalovos on 2018-02-06
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.utils
Critical
John L. Villalovos

Bug Description

So the move from iso8601===0.1.11 to iso8601===0.1.12 broke the unit tests in oslo.utils

iso8601 used to do: from datetime import datetime ...

But now they do: import datetime And then use datetime.datetime()
Unfortunately the unit tests mock datetime.datetime() and now are mocking the one in iso8601. This causes a failure in the unit tests.

The issue is in these two locations:
https://github.com/openstack/oslo.utils/blob/master/oslo_utils/tests/test_timeutils.py#L92
https://github.com/openstack/oslo.utils/blob/master/oslo_utils/tests/test_timeutils.py#L123

The error looks like this:

FAIL: oslo_utils.tests.test_timeutils.TimeUtilsTest.test_is_newer_than_str
----------------------------------------------------------------------
Traceback (most recent call last):
  File "oslo_utils/tests/test_timeutils.py", line 140, in test_is_newer_than_str
    self._test_is_newer_than(timeutils.strtime)
  File "oslo_utils/tests/test_timeutils.py", line 127, in _test_is_newer_than
    59)
  File "oslo_utils/timeutils.py", line 135, in is_newer_than
    return after - utcnow() > datetime.timedelta(seconds=seconds)
TypeError: can't compare datetime.timedelta to MagicMock
======================================================================
FAIL: oslo_utils.tests.test_timeutils.TimeUtilsTest.test_is_older_than_str
----------------------------------------------------------------------
Traceback (most recent call last):
  File "oslo_utils/tests/test_timeutils.py", line 109, in test_is_older_than_str
    self._test_is_older_than(timeutils.strtime)
  File "oslo_utils/tests/test_timeutils.py", line 96, in _test_is_older_than
    59)
  File "oslo_utils/timeutils.py", line 120, in is_older_than
    return utcnow() - before > datetime.timedelta(seconds=seconds)
TypeError: can't compare datetime.timedelta to MagicMock

description: updated

Fix proposed to branch: master
Review: https://review.openstack.org/541142

Changed in oslo.utils:
assignee: nobody → John L. Villalovos (happycamp)
status: New → In Progress
Ben Nemec (bnemec) on 2018-02-06
Changed in oslo.utils:
importance: Undecided → Critical

Reviewed: https://review.openstack.org/541142
Committed: https://git.openstack.org/cgit/openstack/oslo.utils/commit/?id=010fe3b1023871740b57dbc450f80e6c0c0f6e43
Submitter: Zuul
Branch: master

commit 010fe3b1023871740b57dbc450f80e6c0c0f6e43
Author: John L. Villalovos <email address hidden>
Date: Mon Feb 5 22:29:38 2018 -0800

    Fix breaking unit tests due to iso8601 changes

    The move from iso8601===0.1.11 to iso8601===0.1.12 broke unit
    tests in oslo.utils.

    iso8601 used to do:
        from datetime import datetime

    But now they call datetime.datetime():
        import datetime
        datetime.datetime()

    Unfortunately the unit tests that mocked datetime.datetime() are now
    mocking the one in iso8601. This causes a failure in the unit tests.

    Fix this by using the 'wraps' argument to mock. So that the calls will
    get passed through to datetime.datetime. Also changed to using the
    decorator style of mock.

    In addition Python 3 unit tests were broken due to changing how the
    UTC time zone is represented from 'UTC' to 'UTC+00:00'.

    Closes-Bug: #1747575
    Closes-Bug: #1744160
    Change-Id: Ia80ffb5e571cc5366bef2bc1a32c457a3c16843d

Changed in oslo.utils:
status: In Progress → Fix Released

Reviewed: https://review.openstack.org/541543
Committed: https://git.openstack.org/cgit/openstack/oslo.utils/commit/?id=1e0570b2a598b43a85faa28e07ab97d56bf5ba5e
Submitter: Zuul
Branch: stable/queens

commit 1e0570b2a598b43a85faa28e07ab97d56bf5ba5e
Author: John L. Villalovos <email address hidden>
Date: Mon Feb 5 22:29:38 2018 -0800

    Fix breaking unit tests due to iso8601 changes

    The move from iso8601===0.1.11 to iso8601===0.1.12 broke unit
    tests in oslo.utils.

    iso8601 used to do:
        from datetime import datetime

    But now they call datetime.datetime():
        import datetime
        datetime.datetime()

    Unfortunately the unit tests that mocked datetime.datetime() are now
    mocking the one in iso8601. This causes a failure in the unit tests.

    Fix this by using the 'wraps' argument to mock. So that the calls will
    get passed through to datetime.datetime. Also changed to using the
    decorator style of mock.

    In addition Python 3 unit tests were broken due to changing how the
    UTC time zone is represented from 'UTC' to 'UTC+00:00'.

    Closes-Bug: #1747575
    Closes-Bug: #1744160
    Change-Id: Ia80ffb5e571cc5366bef2bc1a32c457a3c16843d
    (cherry picked from commit 010fe3b1023871740b57dbc450f80e6c0c0f6e43)

tags: added: in-stable-queens

This issue was fixed in the openstack/oslo.utils 3.36.0 release.

This issue was fixed in the openstack/oslo.utils 3.35.1 release.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers