Skip to content

Instantly share code, notes, and snippets.

@cansadadeserfeliz
Last active December 28, 2022 09:20
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cansadadeserfeliz/0babd27179ae917c83ea to your computer and use it in GitHub Desktop.
Save cansadadeserfeliz/0babd27179ae917c83ea to your computer and use it in GitHub Desktop.
Mock/replace timezone.now() with a custom date in Django unittes
#! /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
@EliasOPrado
Copy link

cheers

@joelburton
Copy link

thanks!

@akashmugu
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment