Skip to content

Commit

Permalink
Bump to 3.2.5. Fix failing/erroring SubTests not properly reporting o…
Browse files Browse the repository at this point in the history
…utput to stdout/stderr. Resolves #238.
  • Loading branch information
CleanCut committed Nov 23, 2020
1 parent 639a0f4 commit 1403d91
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
# Version 3.2.5
#### 23 Nov 2020

- Fix failing/erroring SubTests not properly reporting output to stdout/stderr. Resolves #238.

# Version 3.2.4
#### 1 Nov 2020

Expand Down
2 changes: 1 addition & 1 deletion green/VERSION
@@ -1 +1 @@
3.2.4
3.2.5
22 changes: 17 additions & 5 deletions green/result.py
Expand Up @@ -363,7 +363,7 @@ def addSubTest(self, test, subtest, err):
"""
Called at the end of a subtest no matter its result.
The test that runs the subtests is calls the other test methods to
The test that runs the subtests calls the other test methods to
record its own result. We use this method to record each subtest as a
separate test result. It's very meta.
"""
Expand Down Expand Up @@ -429,22 +429,34 @@ def __str__(self): # pragma: no cover
def stop(self):
self.shouldStop = True

def tryRecordingStdoutStderr(self, test, proto_test_result):
def tryRecordingStdoutStderr(self, test, proto_test_result, err=None):
if proto_test_result.stdout_output.get(test, False):
self.recordStdout(test, proto_test_result.stdout_output[test])
if proto_test_result.stderr_errput.get(test, False):
self.recordStderr(test, proto_test_result.stderr_errput[test])

# SubTest errors/failures (but not successes) generate a different err object, so we have to
# do some inspection to figure out which object has the output/errput
if (test.class_name == "SubTest") and err:
for t in proto_test_result.stdout_output.keys():
if test.dotted_name.startswith(t.dotted_name):
self.recordStdout(test, proto_test_result.stdout_output[t])
break
for t in proto_test_result.stderr_errput.keys():
if test.dotted_name.startswith(t.dotted_name):
self.recordStderr(test, proto_test_result.stderr_errput[t])
break

def addProtoTestResult(self, proto_test_result):
for test, err in proto_test_result.errors:
self.addError(test, err, proto_test_result.test_time)
self.tryRecordingStdoutStderr(test, proto_test_result)
self.tryRecordingStdoutStderr(test, proto_test_result, err)
for test, err in proto_test_result.expectedFailures:
self.addExpectedFailure(test, err, proto_test_result.test_time)
self.tryRecordingStdoutStderr(test, proto_test_result)
self.tryRecordingStdoutStderr(test, proto_test_result, err)
for test, err in proto_test_result.failures:
self.addFailure(test, err, proto_test_result.test_time)
self.tryRecordingStdoutStderr(test, proto_test_result)
self.tryRecordingStdoutStderr(test, proto_test_result, err)
for test in proto_test_result.passing:
self.addSuccess(test, proto_test_result.test_time)
self.tryRecordingStdoutStderr(test, proto_test_result)
Expand Down
33 changes: 33 additions & 0 deletions green/test/test_result.py
Expand Up @@ -410,6 +410,39 @@ def test_tryRecordingStdoutStderr(self):
gtr.tryRecordingStdoutStderr(test2, ptr2)
gtr.recordStderr.assert_called_with(test2, errput)

def test_tryRecordingStdoutStderr_SubTest(self):
"""
Recording stdout and stderr works correctly for failed/errored SubTests.
"""
gtr = GreenTestResult(self.args, GreenStream(self.stream))
gtr.recordStdout = MagicMock()
gtr.recordStderr = MagicMock()

output = "apple"
test1 = MagicMock()
test1.dotted_name = "test 1"
subtest1 = MagicMock()
subtest1.dotted_name = "test 1: the subtest"
subtest1.class_name = "SubTest"
ptr1 = MagicMock()
ptr1.stdout_output = {test1: output}
ptr1.stderr_errput = {}

errput = "banana"
test2 = MagicMock()
test2.dotted_name = "test 2"
subtest2 = MagicMock()
subtest2.dotted_name = "test 2: subtests are annoying"
subtest2.class_name = "SubTest"
ptr2 = MagicMock()
ptr2.stdout_output = {}
ptr2.stderr_errput = {test2: errput}

gtr.tryRecordingStdoutStderr(subtest1, ptr1, err=True)
gtr.recordStdout.assert_called_with(subtest1, output)
gtr.tryRecordingStdoutStderr(subtest2, ptr2, err=True)
gtr.recordStderr.assert_called_with(subtest2, errput)

def test_failfastAddError(self):
"""
addError triggers failfast when it is set
Expand Down

0 comments on commit 1403d91

Please sign in to comment.