Skip to content

Commit 75a114c

Browse files
committed
Update base CLI test case class where we capture and don't display
captured stdout and stderr to display captured stdout + stderr on test failure. This should make troubleshooting those tests much easier and faster.
1 parent 19e2206 commit 75a114c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

st2client/tests/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ def tearDown(self):
109109
sys.stdout = sys.__stdout__
110110
sys.stderr = sys.__stderr__
111111

112+
# On failure, we also print values of accumulated stdout and stderr
113+
# to make troubleshooting easier
114+
# TODO: nosetests specific make sure to update when / if switching to pytest
115+
errors = getattr(self.__dict__.get("_outcome", None), "errors", [])
116+
117+
if len(errors) >= 1:
118+
stdout = self.stdout.getvalue()
119+
stderr = self.stderr.getvalue()
120+
121+
print("")
122+
print("Captured stdout: %s" % (stdout))
123+
print("Captured stdoerr: %s" % (stderr))
124+
print("")
125+
112126
def _reset_output_streams(self):
113127
"""
114128
Reset / clear stdout and stderr stream.

0 commit comments

Comments
 (0)