Testing timer entrypoint

When testing timer entrypoints (especially now that we have the “eager” argument), I’d like to fire at all so that I can use entrypoint_hook and call it when I want.

So if I have a service

class TestService:
    name = "test_service"

    @timer(10, eager=True)
    def run(self):
       print("yeah")

and a test like this:

def test_service(container_factory):
     container = container_factory(TestService, {})
     container.start()

     with entrypoint_hook(container, "run") as hook:
        hook()

will cause run to be called twice (since it’s called as soon as the container starts as well as within the entrypoint hook. Is there any “nice” way to work around this?

I can do awful stuff like this:

    for entrypoint in list(container.entrypoints):
        if entrypoint.method_name == 'run':
            entrypoint.eager = False  # hack so that it doesn't start right away

but I imagine that is not the nicest way of dealing with this

I think the best solution here would be a pytest fixture that reaches in and modifies the entrypoint somehow, to let people “opt-in” to disable the timer entrypoint.

It would be nice if restrict_entrypoints could be used for this purpose, but unfortunately that would also prevent the entrypoint_hook from working.

You could maybe mock out Timer.handle_timer_tick?