Repository navigation
Drop the test dependency on freezegun - #1632
Open
ShryukGrandhi wants to merge 3 commits into
Open
ShryukGrandhi wants to merge 3 commits into
ShryukGrandhi wants to merge 3 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of changes
freezegun was only used to freeze
datetime.now()in a handful of tests (tests/test_utils.pyand two tests intests/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 intests/_common.py. It swapsdatetime.datetime(and thedatetimename imported bydateutil.utils) for a subclass whosenow()returns the frozen time, and restores the originals afterwards. The subclass uses a metaclass__instancecheck__so thatisinstance(real_dt, datetime.datetime)checks inside dateutil keep working while the patch is active. freezegun is removed fromrequirements-dev.txt, the Python 3.3 requirement/constraint files and the isort config.One test expectation changed:
test_utils_today_tz_info_different_dayasserted thatutils.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 addstz_offseteven whennow()is given an explicit time zone. The correct UTC day is Dec 15, so the test now checks thattoday()(local) gives Dec 16 andtoday(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.pyandtests/test_rrule.pyfail to collect (ModuleNotFoundError: No module named 'freezegun'); after, they pass (745 passed, 1 xfailed). I also checked that removing the@freeze_timedecorators makes the frozen-time tests fail, so the helper is actually doing the freezing. The full suite passes excepttest_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