Re:FreezeGun: easy mocking of Python datetimes
by subleq on Tuesday December 11, 2012 @04:15PM
(#4906864)
Have you tried patching the now() method onto datetime.datetime instead of replacing the whole class? If that doesn't work, you could replace datetime first:
After that, freeze_time would just set a flag on your datetime class.
[ Parent
| on HN ]
Re:FreezeGun: easy mocking of Python datetimes
by madjar on Tuesday December 11, 2012 @04:53PM
(#4907060)
Sadly, it's not possible. datetime is a C class, so it is immutable.
Re:FreezeGun: easy mocking of Python datetimes
by spulec on Tuesday December 11, 2012 @04:57PM
(#4907098)
Correct. I've gone with his latter solution for now and added a warning about import order. I'm not very happy with this solution through and will be spending some time with ctypes in the next few days to come up with something better.