Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
capfd in binary mode? #2923
I'd like something like this to work:
def test_thing(capfd_bytes): subprocess.check_call(('echo', '-e', '\\x98\\xfe')) out, err = capfd_bytes.readouterr() assert out == b'\x98\xfe'
My actual usecase is running
I'm hacking around with this (which works, but is undeniably fragile):
def test(capfd): ... capfd._capture.out.tmpfile.encoding = None capfd._capture.err.tmpfile.encoding = None out, err = capfd.readouterr() capfd._capture.out.tmpfile.encoding = 'UTF-8' capfd._capture.err.tmpfile.encoding = 'UTF-8' # ...
would pytest be amenable to a PR which enables something like this without hax?
It was probably me before
I'm not sure I necessarily like the api I wrote in #2279 (too easy to mix and match bytes / text and get unicode errors when mixing and matching). I think it would be better to add new separate
Rá I knew this has been discussed before.
I think this might be the way to go, it might not be easy to change the stream types after it has been created, and having separate methods is clumsy as you noted.
From my POV please go ahead.