Skip to content

Fix parallel stdout #3

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 28 additions & 4 deletions haas/result.py
Original file line number Diff line number Diff line change
@@ -101,6 +101,25 @@ def _format_exception(err, is_failure, stdout=None, stderr=None):
return ''.join(msgLines)


def _format_output(stdout=None, stderr=None):
"""Format stdout and stderr test output into a single string.

"""
msgLines = []
if stdout is not None:
if not stdout.endswith('\n'):
stdout += '\n'
msgLines.append(STDOUT_LINE % stdout)
if stderr is not None:
if not stderr.endswith('\n'):
stderr += '\n'
msgLines.append(STDERR_LINE % stderr)
if len(msgLines) > 0:
return ''.join(msgLines)
else:
return None


class TestDuration(object):
"""An orderable representation of the duration of an individual test.

@@ -214,21 +233,22 @@ class TestResult(object):
"""

def __init__(self, test_class, test_method_name, status, duration,
exception=None, message=None):
exception=None, message=None, output=None):
self.test_class = test_class
self.test_method_name = test_method_name
self.status = status
self.exception = exception
self.output = output
self.message = message
self.duration = duration

def __repr__(self):
template = ('<{0} class={1}, method={2}, exc={3!r}, status={4!r}, '
'duration={5!r}>')
'duration={5!r}>, output={6!r}')
return template.format(
type(self).__name__, self.test_class.__name__,
self.test_method_name, self.exception, self.status,
self.duration)
self.duration, self.output)

def __eq__(self, other):
if not isinstance(other, TestResult):
@@ -239,6 +259,7 @@ def __eq__(self, other):
self.status == other.status and
self.exception == other.exception and
self.message == other.message and
self.output == other.output and
self.duration == other.duration
)

@@ -269,13 +290,16 @@ def from_test_case(cls, test_case, status, duration,
"""
test_class = type(test_case)
test_method_name = test_case._testMethodName
output = None
if exception is not None:
exctype, value, tb = exception
is_failure = exctype is test_case.failureException
exception = _format_exception(
exception, is_failure, stdout, stderr)
elif stdout is not None or stderr is not None:
output = _format_output(stderr, stdout)
return cls(test_class, test_method_name, status, duration,
exception, message)
exception, message, output)

@property
def test(self):