-
Notifications
You must be signed in to change notification settings - Fork 31
handle '_DuplicateWriter' object has no attribute 'buffer' #56
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
handle '_DuplicateWriter' object has no attribute 'buffer' #56
Conversation
I don't think this works. We're trying to write bytes to this stream, but sys.stdout would normally be accepting str only. |
I've been using this change for a while and I do believe it works, because _DuplicateWriter() is acting as sys.stdout (it overrides the actual sys.stdout) and expects bytes: class _DuplicateWriter(io.TextIOBase):
|
Right, but a regular sys.stdout would not accept bytes. So this might a good workaround for your situation, it's not a proper fix.
Not all platforms provide sys.stdout.buffer, so we should be handling this properly. But we can't expect sys.stdout to handle bytes. |
added type checking for sys.stdout being overridden by unittest-xml-reporting without trying to import the module |
the problem here is that unittest-xml-reporting sets sys.stdout to an odd value; this problem should be fixed in unittest-xml-reporting, rather than worked around in subunit. Alternatively, unittest-xml-reporting could pass in a stream explicitly, in which case subunit wouldn't be trying to access sys.stdout.buffer at all |
Ok, can just scrap this PR then. But it seems like if sys.stdout is overriden by potentially anything (for capture purposes) or buffer is not available like you said, this is still not being handled here. |
Right, subunit can only cope with sys.stdout when it has a buffer attribute that it can use to write byte streams (since sys.stdout should be handling regular strings). We can come across situations in which there is no buffer attribute on some platforms (Python on Android doesn't have it I believe) and if sys.stdout is overridden. There isn't really a good way to deal with a lack of buffer attribute though, since subunit needs to write byte streams. The best thing to do in those situations is for the caller to pass in a byte stream. |
Closing this per discussion |
Handle error case (I believe due to the unittest-xml-reporting module) where sys.stdout has no buffer attribute, causing a failure and hang in subunit:
File "/venv/lib/python3.11/site-packages/subunit/init.py", line 510, in init
stream = sys.stdout.buffer
^^^^^^^^^^^^^^^^^
AttributeError: '_DuplicateWriter' object has no attribute 'buffer'
unittest-xml-reporting/result.py overriding sys.stdout, which doesn't include a buffer: