Skip to content

Drop the test dependency on freezegun - #1632

Open
ShryukGrandhi wants to merge 3 commits into
dateutil:masterfrom
ShryukGrandhi:fix/issue-923-drop-dependency-on-freezegun
Open

ShryukGrandhi wants to merge 3 commits into
dateutil:masterfrom
ShryukGrandhi:fix/issue-923-drop-dependency-on-freezegun

Conversation

@ShryukGrandhi

Copy link
Copy Markdown

Summary of changes

freezegun was only used to freeze datetime.now() in a handful of tests (tests/test_utils.py and two tests in tests/test_rrule.py). It isn't well maintained and also has a circular dependency on dateutil, which makes installing the test requirements awkward.

This replaces it with a small freeze_time(frozen, tz_offset=0) context manager/decorator in tests/_common.py. It swaps datetime.datetime (and the datetime name imported by dateutil.utils) for a subclass whose now() returns the frozen time, and restores the originals afterwards. The subclass uses a metaclass __instancecheck__ so that isinstance(real_dt, datetime.datetime) checks inside dateutil keep working while the patch is active. freezegun is removed from requirements-dev.txt, the Python 3.3 requirement/constraint files and the isort config.

One test expectation changed: test_utils_today_tz_info_different_day asserted that utils.today(UTC) was Dec 16 with the clock frozen at 2014-12-15 23:00 UTC and a +5h local offset. That only held because freezegun adds tz_offset even when now() is given an explicit time zone. The correct UTC day is Dec 15, so the test now checks that today() (local) gives Dec 16 and today(UTC) gives Dec 15, which is what the test name describes.

Tested with a virtualenv that has the dev requirements but not freezegun: before the change, tests/test_utils.py and tests/test_rrule.py fail to collect (ModuleNotFoundError: No module named 'freezegun'); after, they pass (745 passed, 1 xfailed). I also checked that removing the @freeze_time decorators makes the frozen-time tests fail, so the helper is actually doing the freezing. The full suite passes except test_tzpath_data.py::test_dst_matches_tzdata_zi[tzpath], which fails the same way on unmodified master on my machine (system tzdata mismatch).

Fixes #923

Pull Request Checklist

  • Changes have tests
  • Authors have been added to AUTHORS.md
  • News fragment added in changelog.d. See CONTRIBUTING.md for details

Replace freezegun's freeze_time with a minimal helper in tests/_common.py
that patches datetime.datetime.now for the duration of a test.

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
On Python 2 the decorator hides the test's signature from pytest, so the
NYC fixture was not passed.

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>
…p-dependency-on-freezegun

Signed-off-by: ShryukGrandhi <85529990+ShryukGrandhi@users.noreply.github.com>

# Conflicts:
#	pyproject.toml
#	requirements-dev.txt
#	requirements/3.3/constraints.txt
#	requirements/3.3/requirements-dev.txt
#	tests/_common.py
#	tests/test_rrule.py

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drop dependency on freezegun

1 participant