Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JoshM1994/1eae6f090f6add2410b01247cba33852 to your computer and use it in GitHub Desktop.
Save JoshM1994/1eae6f090f6add2410b01247cba33852 to your computer and use it in GitHub Desktop.
Mock calls to asyncio.create_subprocess_shell
# Used to mock calls to asyncio.create_subprocess_shell
# Patches the `communicate` object with a future as specified during construction
import asynctest
import mock
class AsyncioCreateSubprocessShellCommunicateMock:
def __init__(self, future_result):
process_mock = mock.Mock()
future = asynctest.asyncio.Future()
future.set_result(future_result)
attrs = {"communicate.return_value": future}
process_mock.configure_mock(**attrs)
self.mock = process_mock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment