Last active
September 8, 2024 23:22
-
-
Save cansadadeserfeliz/0babd27179ae917c83ea to your computer and use it in GitHub Desktop.
Mock/replace timezone.now() with a custom date in Django unittes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import datetime | |
from mock import patch | |
from django.test import TestCase | |
from django.utils import timezone | |
class DatesTestCase(TestCase): | |
def test_date(self): | |
with patch.object(timezone, 'now', return_value=datetime.datetime(2015, 1, 8, 11, 00)) as mock_now: | |
# some code |
thanks!
👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cheers