-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add several date offset tests in test_filter.py. - Add a new file test_dates.py which patches datetime.date.today() to a fixed date for reproducible date offset testing. - inspirations: https://stackoverflow.com/a/20503374 and https://stackoverflow.com/a/4482067
- Loading branch information
Showing
2 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import datetime | ||
import pytest | ||
|
||
# used for reproducible date offset testing | ||
FIXED_DATE = datetime.date(2020, 3, 25) | ||
|
||
@pytest.fixture | ||
def patch_datetime_today(monkeypatch): | ||
class FixedDate(datetime.date): | ||
@classmethod | ||
def today(cls): | ||
return FIXED_DATE | ||
monkeypatch.setattr(datetime, 'date', FixedDate) | ||
|
||
|
||
def test_patch_datetime(patch_datetime_today): | ||
assert datetime.date.today() == FIXED_DATE |
This file contains 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