Faked time shouldn't always be the same.
See original GitHub issueExcerpt from the docs:
“[…] all calls to datetime.datetime.now()
, datetime.datetime.utcnow()
, […] will return the time that has been frozen.”
But this is not the behaviour I expect.
Example code:
from datetime import datetime
def test_something():
print('now(): ', datetime.now())
print('utcnow():', datetime.utcnow())
Output without Freezegun (system timezone is “Europe/Berlin”):
now(): 2015-03-10 00:46:40.465879
utcnow(): 2015-03-09 23:46:40.466031
Output with Freezegun (method decorated with @freeze_time('2012-03-11 19:21:23')
):
now(): 2012-03-11 19:21:23
utcnow(): 2012-03-11 19:21:23
However, I expected the output with Freezegun to reflect the offset (one hour, in this case) and, thus, to return two different date/time instances.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:43 (7 by maintainers)
Top Results From Across the Web
Why you shouldn't fake happiness at work, according to science
The study showed that being forced to pretend to be happy over long periods of time affected health. “We call this kind of...
Read more >How Your Brain Tricks You Into Believing Fake News - Time
The researchers who conducted the Pew poll noted that one reason people knowingly share made-up news is to “call out” the stories as...
Read more >Murphy's Laws - Cheap Thoughts
Finagle's Laws: 1. If an experiment works, something has gone wrong. 2.1 No matter what result is anticipated, there is always someone willing...
Read more >Faking COVID-19 Illness Can Have Serious Consequences
Employees who fake coronavirus-related illnesses to get out of ... Employers should have clear time-off policies and consider safety first.
Read more >“Fake News” Is Not Simply False Information: A Concept ...
However, human fact-checking can be time consuming and subject to human foibles such as subjectivity and being limited by prior experiences ( ...
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
@charettes For me the point of freeze_time is that you create a world where time related things are predictable and portable across machines. Leaving the time zone as is will not satisfy this demand.
I’m all for having a nicer way to freeze but still respect the time zone if that’s what you want though. I’d also like a better way to “freeze” and still respect the local time! This is super useful to initialize the monkey patching just once for your entire test suite for example. We do this at work (and we use my fork that is also an active PR) and it has some pretty dramatic performance advantages if you freeze time a lot.
I’d suggest this:
freeze_time('local', tzinfo='local', tick=True)
for respecting time zone, local time and keeping the clock movingfreeze_time('2001-01-02', tzinfo='local')
for respecting local time zone but locking the restfreeze_time('2001-01-02')
for locking everything…as for tzinfo vs tzoffset I’m all for it. The only problem I see with it is that if you specify a time zone by name that can mean something different at some later point. tzoffset doesn’t have this problem, but it also doesn’t model DST properly, so I think maybe a third option is needed here? In addition to your suggestion that is.
From this thread we can get some test cases on how it should work, and from the other duplicates as well. I guess no one actually did a full summary of the related issues?
I guess I can give this a shot as I need to work around this right now.