Skip to content

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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion python/subunit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ def test_script_two(self):
PROGRESS_POP = 3


def is_stdout_DuplicateWriter(sys_stdout):
"""
Returns a boolean, type checking sys.stdout to see if it was overriden by the unittest-xml-reporting
module without importing, matching type xmlrunner.result._DuplicateWriter.

@param sys_stdout: The current sys.stdout object.

@return: (bool) True if of type xmlrunner.result._DuplicateWriter, else False.
"""
xmlrunner_module = 'xmlrunner'
if xmlrunner_module in sys.modules:
if hasattr(sys.modules[xmlrunner_module], 'result'):
if hasattr(sys.modules[xmlrunner_module].result, '_DuplicateWriter'):
return isinstance(sys_stdout, sys.modules[xmlrunner_module].result._DuplicateWriter)

return False
else:
return False


def test_suite():
import subunit.tests
return subunit.tests.test_suite()
Expand Down Expand Up @@ -506,7 +526,13 @@ def __init__(self, client, stream=None, forward_stream=None):
"""
self.client = ExtendedToOriginalDecorator(client)
if stream is None:
stream = sys.stdout.buffer
if hasattr(sys.stdout, 'buffer'):
stream = sys.stdout.buffer
else:
# check if sys.stdout was overridden by unittest-xml-reporting module with no buffer
if is_stdout_DuplicateWriter(sys.stdout):
stream = sys.stdout

self._stream = stream
self._forward_stream = forward_stream or DiscardStream()
# state objects we can switch too
Expand Down