You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[…] all calls to datetime.datetime.now(), datetime.datetime.utcnow(), datetime.date.today(), time.time(), time.localtime(), time.gmtime(), and time.strftime() will return the time that has been frozen.
However, in my case I’ve got a subclass of Python’s datetime class that overloads the __new__ function:
The purpose is to enforce aware datetime objects, and requires user to use this custom datetime class instead of Python’s.
However, this approach goes around freezegun which monkeypatches only the above methods. Because I’d really like to switch to using this package (and pytest-freezer or pytest-freezegun) I wanted to ask if you’d consider adding support to patch user-supplied functions?
Problem is that Python’s datetime.__new__ is immutable, so we can’t patch that. But, if I could have the above __new__ patched and freezegun’s features — that’d be great!
The text was updated successfully, but these errors were encountered:
@jenstroeger What did you end up doing to solve your problem? I had a similar issue with a subclass of datetime. I ended up writing a relatively simple wrapper around freezegun that also patches the now() method on my subclass.
@jnrbsn yes pretty much — I wrote a context manager that monkey-patches my subclass’s __new__ and then a pytest fixture that uses that context manager, roughly like so:
This is a great tool and idea, thank you! But…☺️
From the Usage description here:
However, in my case I’ve got a subclass of Python’s datetime class that overloads the
__new__
function:The purpose is to enforce aware datetime objects, and requires user to use this custom
datetime
class instead of Python’s.However, this approach goes around freezegun which monkeypatches only the above methods. Because I’d really like to switch to using this package (and pytest-freezer or pytest-freezegun) I wanted to ask if you’d consider adding support to patch user-supplied functions?
Problem is that Python’s
datetime.__new__
is immutable, so we can’t patch that. But, if I could have the above__new__
patched and freezegun’s features — that’d be great!The text was updated successfully, but these errors were encountered: