Freezegun breaks isinstance() checks on existing objects.
See original GitHub issueIf you have a date object that was created before freezing time, you cannot then do an isinstance check against datetime.date:
>>> date = datetime.date.today()
>>> freezer = freeze_time('2011-01-01')
>>> freezer.start()
>>> isinstance(date, datetime.date)
False
>>>
This is because at the point you call the isinstance, the value of datetime.date is <class 'freezegun.api.FakeDate'>
, of which date
is not a subclass.
Issue Analytics
- State:
- Created 10 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Trying to mock datetime.date.today(), but not working
This one has advantage of not breaking type checking with isinstance(d, datetime.date) . import mock def fixed_today(today): from datetime import date class ...
Read more >python/typing - Gitter
Hello. I have a question on enum and typing. If I overload some function for each available enum values as parameter and then...
Read more >Digging into a Test Failure – A blog for Ted - Ted Mielczarek
I realized that if the database connection was created before any code imported the freezegun module the workaround freezegun was attempting to ...
Read more >How to work with dates and time with Python | Bloomberg LP
When trying to make things work with the datetime module, most Python users have faced a point when we resort to guess-and-check until...
Read more >pytest Documentation - Read the Docs
2.17 How to use pytest with an existing test suite . ... Note: Calling pytest.main() will result in importing your tests and any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not sure. It seems that @spulec hasn’t been on GitHub much lately. He’s likely the only one who can merge, and push releases. It is possible to reference a git-commit in a
requirements.txt
: you may have to do that until he has time to merge/push.I am also a contributor that can merge. Unfortunately I can’t cut releases to pypi at this time.