-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
capsys not implementing fileno, patches stream object causing io error #10154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have a smiliar issue. Anything tips how to deal with it? Would be very important for my project to catch stdout... def test_run(self, capsys):
import subprocess
import sys
p = subprocess.Popen(["echo", "123"], stdout=sys.stdout)
p.wait()
stdout = capsys.readouterr().out raises /usr/lib/python3.11/subprocess.py:992: in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Popen: returncode: None args: ['echo', '123']>, stdin = None, stdout = <_io.TextIOWrapper encoding='UTF-8'>, stderr = None
def _get_handles(self, stdin, stdout, stderr):
"""Construct and return tuple with IO objects:
p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite
...
elif stdout == DEVNULL:
c2pwrite = self._get_devnull()
elif isinstance(stdout, int):
c2pwrite = stdout
else:
# Assuming file-like object
> c2pwrite = stdout.fileno()
E io.UnsupportedOperation: fileno
/usr/lib/python3.11/subprocess.py:1723: UnsupportedOperation |
@kmille sys capture will never support subprocesses, please use a supported mechanism |
Closing this as not planned, sys capture uses bytes/stringio and will never support file no Use fdcapture if a file number is needed |
Can you give an example or docs about fdcapture? Sorry it's not clear to me. |
@kmille what its completely and utterly surreal to me is that you want to pass a capture to a sub-process call instead of just using something like |
Pytest 7.1.0
plugins: asyncio-0.19.0, repeat-0.9.1
When using the
capsys
fixture, starting an async StreamWriter using thestdout
orstderr
pipes fails under test and works in regular Python.It looks like this is because the
capsys
fixture sets different behaviours to the regular pipe objectThe text was updated successfully, but these errors were encountered: