I want to capture and analyze output for a function which do this:
subprocess.call(args, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr)
When I run this code without any mocks under py.test I get error: ValueError: redirected Stdin is pseudofile, has no fileno()
When I patch sys.stdin (and others) with mock I get the same error.
When I patch sys.stdin with mock.mock_open()
I get error: AttributeError: Mock object has no attribute 'write'
When I patch sys.stdin with mock.mock_open()('name', 'r')
I get initial error: ValueError: redirected Stdin is pseudofile, has no fileno()
Is any way to pass some kind of mock object as stdin/out for subprocess?
I want something like this:
mocked = (put something here)
subprocess_call('ls', stdin=mocked, stdout=mocked, stderr=mocked)
Which should work when run under py.test.
Thanks.