Handle case of no logging environment variables

When running functional tests manually, the expected environment variables
typically set by tox may not be set.  This patch avoids an exception and
lets the test run with the defaults.

Change-Id: I62c2e8cac3ed2292f7762bc9d9da6b3d7b969e28
Closes-bug: #1496826
This commit is contained in:
Dave McCowan 2015-09-17 22:37:02 -04:00
parent ecfa4beee9
commit dd932a96d9
1 changed files with 10 additions and 6 deletions

View File

@ -53,16 +53,20 @@ class TestCase(oslotest.BaseTestCase):
self.client = client.BarbicanClient()
if (os.environ.get('OS_STDOUT_CAPTURE').lower() == 'true' or
os.environ.get('OS_STDOUT_CAPTURE') == '1'):
stdout_capture = os.environ.get('OS_STDOUT_CAPTURE')
stderr_capture = os.environ.get('OS_STDERR_CAPTURE')
log_capture = os.environ.get('OS_LOG_CAPTURE')
if ((stdout_capture and stdout_capture.lower() == 'true') or
stdout_capture == '1'):
stdout = self.useFixture(fixtures.StringStream('stdout')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout))
if (os.environ.get('OS_STDERR_CAPTURE').lower() == 'true' or
os.environ.get('OS_STDERR_CAPTURE') == '1'):
if ((stderr_capture and stderr_capture.lower() == 'true') or
stderr_capture == '1'):
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
if (os.environ.get('OS_LOG_CAPTURE').lower() == 'true' or
os.environ.get('OS_LOG_CAPTURE') == '1'):
if ((log_capture and log_capture.lower() == 'true') or
log_capture == '1'):
self.useFixture(fixtures.LoggerFixture(nuke_handlers=False,
format=self.log_format,
level=logging.DEBUG))