a library that allows your python tests to travel through time by mocking the datetime module
Questions tagged [freezegun]
24 questions
2
votes
1 answer
how to use freezegun on logbook
I'm trying to run tests that involve mocking datetime within logbook (for logic around logbook.TimedRotatingFileHandler). But freezegun doesn't reach logbook. Logs print as the current (un-mocked, correct) current time!
my example prints the…

Will
- 1,206
- 9
- 22
2
votes
1 answer
How do I freeze time and assert on a timestamp in a template?
p1/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('t1/', views.t1),
]
p1/views.py:
from django.shortcuts import render
def t1(request):
return render(request, 'p1/t1.html')
p1/templates/p1/t1.html:

x-yuri
- 16,722
- 15
- 114
- 161
1
vote
1 answer
Freezegun does not work on django orm create_at field
I am trying to use freezegun for unittest:
class Customer(models.Model):
created_at = models.DateTimeField(default=datetime.now, null=True)
from freezegun import freeze_time
with freeze_time(datetime(2020, 9, 9, 9),…

zcahfg2
- 861
- 1
- 12
- 27
1
vote
1 answer
Freeze Time test cases fail when a variable is used to reference the time
I'm using freeze-time to run my python unittest Test cases.
A dummy test case:
@freeze_time('2020-01-01')
def test_something(self):
expected_output = {'time': '2020-01-01'}
output = call_tested_code()
self.assertEqual(expected_output,…

piyush daga
- 501
- 4
- 17
1
vote
0 answers
freeze_time `ignore` doesn't seem to work in more complicated setup (Django + S3 / boto)
I am using Django with S3 as the file storage (which uses boto3/botocore libs). I have a "management" command which creates some Django instances - I use freezegun, so these instances appear to be created in the past. However some of these models…

radoh
- 4,554
- 5
- 30
- 45
1
vote
1 answer
Why does datetime.utcnow not behave as I'd expect with freezegun?
I've noticed something which I don't understand, and I'm wondering if anyone could shed some light on it.
In short: if
x = datetime.datetime.utcnow
and
y = lambda: datetime.datetime.utcnow()
I would expect x() and y() to behave the same, always.…

gimboland
- 1,926
- 2
- 19
- 28
1
vote
1 answer
How can I figure out what line of Python code is generating a PendingDeprecationWarning?
I have a set of Python 3 unittests, which, when executed with this command line:
python3 -m unittest discover -f -v
...are generating a…

Andrew Ferrier
- 16,664
- 13
- 47
- 76
0
votes
1 answer
Freezetime does not work with FastAPI test client
Freezetime does not seem to work with FastAPI TestClient.
I have build this simple example, the test is failing.
Freezetime does not override datetime in this case :/
import datetime
from fastapi import FastAPI
from fastapi.testclient import…

dan
- 1
- 1
0
votes
1 answer
freeze_time doesn't work inside invoked functions
# test.py
from freezegun import freeze_time
from actual import DummyClass
class DummyClassMock(DummyClass):
def some_function(self):
# does something
class TestClass():
def setUp(self):
self.dummy = DummyClassMock()
…

mounika
- 39
- 8