# Testing timer entrypoint

**URL:** <https://discourse.nameko.io/t/testing-timer-entrypoint/494>\
**Category:** Uncategorized\
**Created:** [September 9, 2019, 2:20pm UTC](https://discourse.nameko.io/t/testing-timer-entrypoint/494 "2019-09-09T14:20:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davis\_Kirkendall](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/davis_kirkendall/32/18_2.png) [@Davis\_Kirkendall](https://discourse.nameko.io/u/Davis_Kirkendall)\
**Post date:** [September 9, 2019, 2:20pm UTC](https://discourse.nameko.io/t/testing-timer-entrypoint/494/1 "2019-09-09T14:20:52Z")

</div>

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

```python
class TestService:
    name = "test_service"

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

```

and a test like this:

```python
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:

```python
    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

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [September 9, 2019, 3:10pm UTC](https://discourse.nameko.io/t/testing-timer-entrypoint/494/2 "2019-09-09T15:10:58Z")

</div>

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`?
