Make Freezegun work with SqlAlchemyΒΆ
Freezegun allows to freeze time during tests, this is particularly useful when testing APIs with timestamps.
By default freezegun does not work well with SqlAlchemy, the timestamps it generates are not frozen.
You can use the following approach to make freezegun work with SqlAlchemy
class Model(Base):
...
created_at = Column(DateTime, default=datetime.utcnow)
...
def _now():
return datetime.utcnow()
class Model(Base):
...
created_at = Column(DateTime, default=_now)
...
Freezegun documentation : https://github.com/spulec/freezegun