Capture the stdout and stderr based on environment

Capture the stdout and stderr based on the environment variable
OS_STDOUT_CAPTURE and OS_STDERR_CAPTURE. This is helpful for using
pdb and ipdb for debug.
This patch does not change the behavior of testr, because the
variables are set to 1 in `.testr.conf` file.

Change-Id: I66d01875a6253524bafddf1b4e20f9126466034e
This commit is contained in:
Jeffrey Zhang 2014-09-26 12:08:50 +08:00
parent 0f75fdc64c
commit 25cd3d3e67

View File

@ -36,10 +36,12 @@ class TestBase(testtools.TestCase):
self.useFixture(fixtures.FakeLogger('zaqar'))
# NOTE(kgriffs): Don't monkey-patch stdout since it breaks
# debugging with pdb.
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
if os.environ.get('OS_STDOUT_CAPTURE') is not None:
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
if os.environ.get('OS_STDERR_CAPTURE') is not None:
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
if self.config_file:
self.conf = self.load_conf(self.config_file)