question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nesting freeze_time doesn't work with time.time()

See original GitHub issue
@freeze_time('2015-01-01')
def test_method(self):
    print time(), datetime.utcnow()
    with freeze_time('2015-01-01T00:06:00'):
        print time(), datetime.utcnow()

Yields:

1420070400.0 2015-01-01 00:00:00
1420070400.0 2015-01-01 00:06:00
$ pip show freezegun

---
Name: freezegun
Version: 0.3.5
Location: /home/____/paxon/env/lib/python2.7/site-packages
Requires: six, python-dateutil

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
boxedcommented, Sep 10, 2018

From a very cursory inspection of api.py it looks like this is the start of the problem:

        datetime.datetime = FakeDatetime
        datetime.date = FakeDate
        fake_time = FakeTime(time_to_freeze, time.time)
        fake_localtime = FakeLocalTime(time_to_freeze, time.localtime)
        fake_gmtime = FakeGMTTime(time_to_freeze, time.gmtime)
        fake_strftime = FakeStrfTime(time_to_freeze, time.strftime)

and later

        datetime.datetime.times_to_freeze.append(time_to_freeze)
        datetime.datetime.tz_offsets.append(self.tz_offset)

        datetime.date.dates_to_freeze.append(time_to_freeze)
        datetime.date.tz_offsets.append(self.tz_offset)

The nesting works because the second block, which is not implemented for the birst blocks. It looks like the code could be simplified a lot if this was unified too, so instead of

        datetime.date.dates_to_freeze.append(time_to_freeze)
        datetime.date.tz_offsets.append(self.tz_offset)

you could have

for foo in fakes:
    foo.times_to_freeze.append(time_to_freeze)
    foo.tz_offsets.append(self.tz_offset)

or similar but better named obviously.

0reactions
spuleccommented, Oct 15, 2018

Closed with #260

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to use freezegun on logbook - Stack Overflow
I'm trying to run tests that involve mocking datetime within logbook (for logic around logbook.TimedRotatingFileHandler ). But freezegun doesn't ...
Read more >
Scheduling: setTimeout and setInterval
Nested setTimeout calls are a more flexible alternative to setInterval , allowing us to set the time between executions more precisely. Zero ...
Read more >
Time-stretching and time-remapping - Adobe Support
In a Composition or Timeline panel, select the layer. Place the current-time indicator on the frame that you want to freeze.
Read more >
Troubleshoot strange heating or cooling behavior
If your system doesn't work correctly with your old thermostat and you see the same issues you had with the Nest thermostat, your...
Read more >
setTimeout() - Web APIs - MDN Web Docs
Working with asynchronous functions ... setTimeout() is an asynchronous function, meaning that the timer function will not pause execution of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found