{"action":"created","issue":{"url":"https://api.github.com/repos/celery/celery/issues/3642","repository_url":"https://api.github.com/repos/celery/celery","labels_url":"https://api.github.com/repos/celery/celery/issues/3642/labels{/name}","comments_url":"https://api.github.com/repos/celery/celery/issues/3642/comments","events_url":"https://api.github.com/repos/celery/celery/issues/3642/events","html_url":"https://github.com/celery/celery/issues/3642","id":192976192,"number":3642,"title":"pytest plugin example fails with `NotRegistered`","user":{"login":"mbattifarano","id":1844175,"avatar_url":"https://avatars1.githubusercontent.com/u/1844175?v=4","gravatar_id":"","url":"https://api.github.com/users/mbattifarano","html_url":"https://github.com/mbattifarano","followers_url":"https://api.github.com/users/mbattifarano/followers","following_url":"https://api.github.com/users/mbattifarano/following{/other_user}","gists_url":"https://api.github.com/users/mbattifarano/gists{/gist_id}","starred_url":"https://api.github.com/users/mbattifarano/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbattifarano/subscriptions","organizations_url":"https://api.github.com/users/mbattifarano/orgs","repos_url":"https://api.github.com/users/mbattifarano/repos","events_url":"https://api.github.com/users/mbattifarano/events{/privacy}","received_events_url":"https://api.github.com/users/mbattifarano/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/celery/celery/milestones/7","html_url":"https://github.com/celery/celery/milestone/7","labels_url":"https://api.github.com/repos/celery/celery/milestones/7/labels","id":592,"number":7,"title":"v5.0.0","description":"Release 5.0.0 which breaks backwards compatibility, drops Legacy Python (python2) support and more.","creator":{"login":"ask","id":1558,"avatar_url":"https://avatars2.githubusercontent.com/u/1558?v=4","gravatar_id":"","url":"https://api.github.com/users/ask","html_url":"https://github.com/ask","followers_url":"https://api.github.com/users/ask/followers","following_url":"https://api.github.com/users/ask/following{/other_user}","gists_url":"https://api.github.com/users/ask/gists{/gist_id}","starred_url":"https://api.github.com/users/ask/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ask/subscriptions","organizations_url":"https://api.github.com/users/ask/orgs","repos_url":"https://api.github.com/users/ask/repos","events_url":"https://api.github.com/users/ask/events{/privacy}","received_events_url":"https://api.github.com/users/ask/received_events","type":"User","site_admin":false},"open_issues":155,"closed_issues":18,"state":"open","created_at":"2011-04-10T12:50:55Z","updated_at":"2018-02-22T04:16:36Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2016-12-01T22:07:42Z","updated_at":"2018-02-27T22:58:13Z","closed_at":null,"author_association":"NONE","body":"## Checklist\r\n\r\n- [x] I have included the output of ``celery -A proj report`` in the issue.\r\n      (if you are not able to do this, then at least specify the Celery\r\n       version affected). -- This failure happens using only the pytest plugin fixtures\r\n- [x] I have verified that the issue exists against the `master` branch of Celery.\r\n\r\n## Steps to reproduce\r\n\r\nVersions: Celery 4.0.0 (and master), pytest 3.0.4 with the plugin from `celery/contrib/pytest.py`\r\n\r\n+ Copy and paste the example test from the [docs](http://docs.celeryproject.org/en/master/userguide/testing.html#celery-app-celery-app-used-for-testing) into a file. \r\n+ Run `pytest test_tasks.py`\r\n\r\n`test_tasks.py`:\r\n```python\r\ndef test_create_task(celery_app, celery_worker):\r\n    @celery_app.task\r\n    def mul(x, y):\r\n        return x * y\r\n\r\n    assert mul.delay(4, 4).get(timeout=10) == 16\r\n```\r\n\r\n## Expected behavior\r\n\r\nThe test passes\r\n\r\n## Actual behavior\r\n\r\nA `NotRegistered` exception is raised on `assert mul.delay(4, 4).get(timeout=10) == 16`:\r\n\r\n```\r\n_______________________________________________ test_create_task ________________________________________________\r\n\r\ncelery_app = <Celery celery.tests:0x10369ff50>, celery_worker = <Worker: gen71974@mbhome.local (running)>\r\n\r\n    def test_create_task(celery_app, celery_worker):\r\n        @celery_app.task\r\n        def mul(x, y):\r\n            return x * y\r\n    \r\n>       assert mul.delay(4, 4).get(timeout=10) == 16\r\n\r\ntest_tasks.py:6: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n[...]/celery/celery/result.py:189: in get\r\n    on_message=on_message,\r\n[...]/celery/celery/backends/base.py:470: in wait_for_pending\r\n    return result.maybe_throw(propagate=propagate, callback=callback)\r\n[...]/celery/celery/result.py:294: in maybe_throw\r\n    self.throw(value, self._to_remote_traceback(tb))\r\n[...]/celery/celery/result.py:287: in throw\r\n    self.on_ready.throw(*args, **kwargs)\r\n../.virtualenvs/celery-dev/lib/python2.7/site-packages/vine-1.1.3-py2.7.egg/vine/promises.py:213: in throw\r\n    reraise(type(exc), exc, tb)\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n\r\ntp = <class 'celery.backends.base.NotRegistered'>, value = NotRegistered(u\"u'test_tasks.mul'\",), tb = None\r\n\r\n>   ???\r\nE   NotRegistered: u'test_tasks.mul'\r\n\r\n<string>:1: NotRegistered\r\n--------------------------------------------- Captured stderr call ----------------------------------------------\r\n[2016-12-01 16:49:43,763: ERROR/MainProcess] Received unregistered task of type u'test_tasks.mul'.\r\nThe message has been ignored and discarded.\r\n\r\nDid you remember to import the module containing this task?\r\nOr maybe you're using relative imports?\r\n\r\nPlease see\r\nhttp://docs.celeryq.org/en/latest/internals/protocol.html\r\nfor more information.\r\n\r\nThe full contents of the message body was:\r\n'[[4, 4], {}, {\"chord\": null, \"callbacks\": null, \"errbacks\": null, \"chain\": null}]' (81b)\r\nTraceback (most recent call last):\r\n  File \"[...]/celery/celery/worker/consumer/consumer.py\", line 558, in on_task_received\r\n    strategy = strategies[type_]\r\nKeyError: u'test_tasks.mul'\r\n```"},"comment":{"url":"https://api.github.com/repos/celery/celery/issues/comments/369057682","html_url":"https://github.com/celery/celery/issues/3642#issuecomment-369057682","issue_url":"https://api.github.com/repos/celery/celery/issues/3642","id":369057682,"user":{"login":"sergii-tkachenko","id":672669,"avatar_url":"https://avatars2.githubusercontent.com/u/672669?v=4","gravatar_id":"","url":"https://api.github.com/users/sergii-tkachenko","html_url":"https://github.com/sergii-tkachenko","followers_url":"https://api.github.com/users/sergii-tkachenko/followers","following_url":"https://api.github.com/users/sergii-tkachenko/following{/other_user}","gists_url":"https://api.github.com/users/sergii-tkachenko/gists{/gist_id}","starred_url":"https://api.github.com/users/sergii-tkachenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergii-tkachenko/subscriptions","organizations_url":"https://api.github.com/users/sergii-tkachenko/orgs","repos_url":"https://api.github.com/users/sergii-tkachenko/repos","events_url":"https://api.github.com/users/sergii-tkachenko/events{/privacy}","received_events_url":"https://api.github.com/users/sergii-tkachenko/received_events","type":"User","site_admin":false},"created_at":"2018-02-27T22:58:13Z","updated_at":"2018-02-27T22:58:13Z","author_association":"NONE","body":"I was able to get it done using `celery_worker.reload()`:\r\n```py\r\ndef test_on_timeout(celery_app, celery_worker):\r\n    @celery_app.task()\r\n    def test_task():\r\n        return True\r\n\r\n    # Reload worker to add test_task to its registry.\r\n    celery_worker.reload()\r\n\r\n    test_task.apply_async()\r\n```\r\n\r\nThis will force `celery_worker` to register the task."}}
{"actor":{"display_login":"sergii-tkachenko"}}