{"action":"created","issue":{"url":"https://api.github.com/repos/nvie/rq/issues/367","repository_url":"https://api.github.com/repos/nvie/rq","labels_url":"https://api.github.com/repos/nvie/rq/issues/367/labels{/name}","comments_url":"https://api.github.com/repos/nvie/rq/issues/367/comments","events_url":"https://api.github.com/repos/nvie/rq/issues/367/events","html_url":"https://github.com/nvie/rq/issues/367","id":36404211,"number":367,"title":"Run Worker.work in same process without forking for Unit Testing + Mocking support","user":{"login":"robodude666","id":172501,"avatar_url":"https://avatars.githubusercontent.com/u/172501?v=3","gravatar_id":"","url":"https://api.github.com/users/robodude666","html_url":"https://github.com/robodude666","followers_url":"https://api.github.com/users/robodude666/followers","following_url":"https://api.github.com/users/robodude666/following{/other_user}","gists_url":"https://api.github.com/users/robodude666/gists{/gist_id}","starred_url":"https://api.github.com/users/robodude666/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robodude666/subscriptions","organizations_url":"https://api.github.com/users/robodude666/orgs","repos_url":"https://api.github.com/users/robodude666/repos","events_url":"https://api.github.com/users/robodude666/events{/privacy}","received_events_url":"https://api.github.com/users/robodude666/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2014-06-24T17:03:14Z","updated_at":"2016-09-19T00:44:14Z","closed_at":"2014-09-11T15:29:27Z","body":"Would it be difficult to support being able to run:\r\n\r\n```python\r\nq = Queue()\r\nw = Worker(q)\r\nw.work(True)\r\n```\r\n\r\nin the same process the worker is created in without forking? I know I can make a subclass of Worker that forgoes forking, but it would nice to make rq more Unit Testing, and Mock friendly.\r\n\r\nCurrently if I want to mock anything that is ran inside of a job, I need to mock out `os.fork` to return `0` and `os._exit` to not do anything. This will force the worker to run in the same process, and allow my `mock.patch`. If I do not, then the rq job will run and not share the same mock objects.\r\n\r\nIf there are ways of doing this with `mock` and `rq` as-is, then I'd be happy to learn as I'm fairly new to `mock`.\r\n"},"comment":{"url":"https://api.github.com/repos/nvie/rq/issues/comments/247894802","html_url":"https://github.com/nvie/rq/issues/367#issuecomment-247894802","issue_url":"https://api.github.com/repos/nvie/rq/issues/367","id":247894802,"user":{"login":"nabilm","id":987369,"avatar_url":"https://avatars.githubusercontent.com/u/987369?v=3","gravatar_id":"","url":"https://api.github.com/users/nabilm","html_url":"https://github.com/nabilm","followers_url":"https://api.github.com/users/nabilm/followers","following_url":"https://api.github.com/users/nabilm/following{/other_user}","gists_url":"https://api.github.com/users/nabilm/gists{/gist_id}","starred_url":"https://api.github.com/users/nabilm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nabilm/subscriptions","organizations_url":"https://api.github.com/users/nabilm/orgs","repos_url":"https://api.github.com/users/nabilm/repos","events_url":"https://api.github.com/users/nabilm/events{/privacy}","received_events_url":"https://api.github.com/users/nabilm/received_events","type":"User","site_admin":false},"created_at":"2016-09-19T00:44:14Z","updated_at":"2016-09-19T00:44:14Z","body":"This is never worked ! i don't see something in the code flow that depends on the async argument you always call the resolve_connection ! and it 'll always raise error \r\n 57     def __init__(self, name='default', default_timeout=None, connection=None,\r\n     58                  async=True, job_class=None):\r\n---> 59         self.connection = resolve_connection(connection)\r\n     60         prefix = self.redis_queue_namespace_prefix\r\n     61         self.name = name\r\n\r\n/home/vagrant/coolblue2/local/lib/python2.7/site-packages/rq/connections.pyc in resolve_connection(connection)\r\n     68     connection = get_current_connection()\r\n     69     if connection is None:\r\n---> 70         raise NoRedisConnectionException('Could not resolve a Redis connection')\r\n     71     return connection\r\n     72\r\n\r\nNoRedisConnectionException: Could not resolve a Redis connection"}}
{"actor":{"display_login":"nabilm"}}