That's what I've been doing, but not because I believe it to be a better way, but because I'm to lazy to implement my own FreezeGun. I don't think the production code should contain unnecessary complexity that is only used for testing.
What about those of us who prefer the simpler time module (which works mostly in epoch time)? It would be a simple change to extend FreezeGun to cover that module in a similar way, surely?
Hey 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.
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:
import freezegun; freezegun.monkey_patch()
from datetime import datetime
After that, freeze_time would just set a flag on your datetime class.
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.
I don't really have much experience in datetimes I guess. What is this really good for? Can someone provide some use cases where this library might be helpful?
https://github.com/travisjeffery/timecop
https://github.com/bebanjo/delorean
In the ruby community, disliking someone's choice of science fiction reference is grounds for a rewrite.