8 ms·
Cool, but unfortunately it breaks if the code your testing does from datetime import datetime :( https://gist.github.com/4261936 https://gist.github.com/426193
by TimothyFitz 14y ago
Cool, but unfortunately it breaks if the code your testing does from datetime import datetime :(
https://gist.github.com/4261936 https://gist.github.com/4261936
- spulec 14y agoHey Timothy, thanks for the response. You are correct. I'll add a warning to the library and work on a solution. Unfortunately, I think it will need to involve ctypes.
- subleq 14y agoHave 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: import freezegun; freezegun.monkey_patch() from datetime import datetime After that, freeze_time would just set a flag on your datetime class.
- madjar 14y agoSadly, it's not possible. datetime is a C class, so it is immutable.
- spulec 14y agoCorrect. 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.