freezegun icon indicating copy to clipboard operation
freezegun copied to clipboard

move_to not supported when ticks enabled

Open thehesiod opened this issue 4 years ago • 5 comments

it seems like only StepTickTimeFactory and FrozenDateTimeFactory have this method enabled but not TickingDateTimeFactory

thehesiod avatar May 22 '20 21:05 thehesiod

Thanks for opening! I am marking this as an enhancement.

spulec avatar May 23 '20 23:05 spulec

is it really an enhancement? The docs say this should work. Btw here's my hack around it:

class WraptTickingDateTimeFactory(wrapt.ObjectProxy):
    # https://github.com/spulec/freezegun/issues/350
    def move_to(self, target_datetime):
        """Moves frozen date to the given ``target_datetime``"""
        self.__wrapped__.time_to_freeze = freezegun.api._parse_time_to_freeze(target_datetime)
        self.__wrapped__.start = freezegun.api.real_datetime.now()

    if isinstance(frozen_datetime, freezegun.api.TickingDateTimeFactory):
        frozen_datetime = WraptTickingDateTimeFactory(frozen_datetime)

thehesiod avatar May 23 '20 23:05 thehesiod

What's the status of this? It's really frustrating, especially when used together with pytest-freezegun library, which does not allow to change the original factory of the freezer fixture on the fly.

lokhman avatar Aug 31 '22 20:08 lokhman

The status is there is no PR to fix it.

boxed avatar Sep 01 '22 04:09 boxed

We need a PR! :)

lokhman avatar Sep 01 '22 08:09 lokhman

https://github.com/spulec/freezegun/pull/531 I'm not sure where to add tests for this. Also, is the reset of start really required?

ashishnitinpatil avatar Feb 11 '24 07:02 ashishnitinpatil

Created a PR for this - https://github.com/spulec/freezegun/pull/533 For the time being, to circumvent the issue, you could (if possible) simply add the argument auto_tick_seconds=1 to your freeze_time call.

ashishnitinpatil avatar Feb 16 '24 11:02 ashishnitinpatil