Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete copying freezegun API #20

Closed
2 of 4 tasks
adamchainz opened this issue May 29, 2020 · 8 comments
Closed
2 of 4 tasks

Complete copying freezegun API #20

adamchainz opened this issue May 29, 2020 · 8 comments

Comments

@adamchainz
Copy link
Owner

adamchainz commented May 29, 2020

  • .tick() method
  • .move_to() method
  • auto_tick_seconds(?) - Add auto_tick_seconds #14
  • Wrapping non-TestCase classes like pytest classes. Probably adopt the unittest mechanism where only callables starting test_ (or a configurable prefix) are wrapped, rather than the unnecessary, perhaps dangerous "wrap every callable" behaviour freezegun uses.
@alex-verve
Copy link
Contributor

@adamchainz do you need help with implementing .tick() method? If so I think I can help with that. Also if you have particular idea how it should be implemented feel free to instruct me :)

@adamchainz
Copy link
Owner Author

Help with any of it would be great! These methods should all be implementable in the python side of things so no need to dive into the C. No particular idea right now, show me what you come up with!

adamchainz added a commit that referenced this issue Jun 6, 2020
Refs #20.

Co-authored-by: alex-verve <alex.subbotin@pollen.co>
Co-authored-by: Adam Johnson <me@adamj.eu>
@adamchainz
Copy link
Owner Author

I've closed #14 because I don't want to add auto_tick_seconds until there's a request. I'm not sure of all the use cases - personally I feel it's more useful to directly control time in tests with tick=True / shift() / move_to().

@alex-verve
Copy link
Contributor

There is an ignore argument in freezgun lib which seems to be useful sometimes (in my case boto3 upload was failing due to RequestTimeTooSkewed error).
I'm not sure if it's possible to implement it in time-machine tho.

For now I'm using workaround like following:

from contextlib import contextmanager
from time_machine import coordinates_stack


@contextmanager
def disable_time_machine():
    global coordinates_stack

    original_coordinates_stack = coordinates_stack.copy()
    coordinates_stack.clear()
    yield
    coordinates_stack.extend(original_coordinates_stack)

@adamchainz
Copy link
Owner Author

The only way we could implement it would be through stack inspection to find the caller, and I don't think it's worth that level of complexity.

If you need to disable time-machine for a block of code you can wrap just certain blocks of code with the context manager, or use the start/stop API. You could also possibly work around it with an inner travel() to the current time - possibly we could support destination=time_machine.REAL_TIME or similar to support that case.

@alex-verve
Copy link
Contributor

destination=time_machine.REAL_TIME sounds like the optimal solution (at least in my case)

@adamchainz
Copy link
Owner Author

FYI you can use the escape_hatch API now to get the real time: https://github.com/adamchainz/time-machine#escape_hatch

@adamchainz
Copy link
Owner Author

Decided not to wrap non-TestCase classes in #187. I think that's all the features we wanted to copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants