Skip to content

Instantly share code, notes, and snippets.

@kipanshi
Created April 18, 2012 14:00
Show Gist options
  • Save kipanshi/2413788 to your computer and use it in GitHub Desktop.
Save kipanshi/2413788 to your computer and use it in GitHub Desktop.
Mock datetime.now() for testing
class FakeDatetimeFactory(object):
"""Factory to help testing logic depending on ``datetime.now()``.
"""
@classmethod
def now(self, *args, **kwargs):
class FakeDatetime(datetime):
"""Datetime class with overriden ``now()`` method."""
@classmethod
def now(cls):
return cls(*args, **kwargs)
return FakeDatetime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment