From 25cd3d3e67a50b57b4a668c8de70bb006956adb4 Mon Sep 17 00:00:00 2001 From: Jeffrey Zhang Date: Fri, 26 Sep 2014 12:08:50 +0800 Subject: [PATCH] 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 --- zaqar/tests/base.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zaqar/tests/base.py b/zaqar/tests/base.py index 1faa5ac45..4002f0381 100644 --- a/zaqar/tests/base.py +++ b/zaqar/tests/base.py @@ -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)