From 7224fde0f0d6206136b411276f8ee8bce8749dd1 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Mon, 7 Jan 2013 11:03:30 -0800 Subject: [PATCH] Invert test stream capture logic for debugging. Previously the default test behavior was to capture stdout and stderr. Make the new default to not capture stdout and stderr then set .testr.conf to always capture these streams when running tests under testr. The motiviation behind this change is that you will want these streams to be captured when running under testr, but when not running under testr you may not want to capture them. An example of this would be running `python -m testtools.run test_name` with a change to test_name to invoke the python debugger (capturing stdout and stderr interferes with normal debugger functionality). Also, only invoke the test timeout by default when running under testr. This is done for the same reason as above. When running a test under the debugger the timeout interferes with debugging. Change-Id: I42cbbdadb2f221ec439e92a6800d14e8436bb77b --- .testr.conf | 2 +- nova/test.py | 18 ++++++++++++------ run_tests.sh | 2 -- tox.ini | 3 --- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.testr.conf b/.testr.conf index fd9442349bdf..1036ba0ca0ed 100644 --- a/.testr.conf +++ b/.testr.conf @@ -1,4 +1,4 @@ [DEFAULT] -test_command=${PYTHON:-python} -m subunit.run discover -t ./ ./nova/tests $LISTOPT $IDOPTION +test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 ${PYTHON:-python} -m subunit.run discover -t ./ ./nova/tests $LISTOPT $IDOPTION test_id_option=--load-list $IDFILE test_list_option=--list diff --git a/nova/test.py b/nova/test.py index fd9c4a522d34..3fc25b12f647 100644 --- a/nova/test.py +++ b/nova/test.py @@ -191,17 +191,23 @@ class TestCase(testtools.TestCase): def setUp(self): """Run before each test method to initialize test environment.""" super(TestCase, self).setUp() - # Give each test a maximum of one minute to run. - self.useFixture(fixtures.Timeout(60, gentle=True)) + test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0) + try: + test_timeout = int(test_timeout) + except ValueError: + # If timeout value is invalid do not set a timeout. + test_timeout = 0 + if test_timeout > 0: + self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.NestedTempfile()) self.useFixture(fixtures.TempHomeDir()) - if (os.environ.get('OS_STDOUT_NOCAPTURE') != 'True' and - os.environ.get('OS_STDOUT_NOCAPTURE') != '1'): + if (os.environ.get('OS_STDOUT_CAPTURE') == 'True' or + os.environ.get('OS_STDOUT_CAPTURE') == '1'): stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', stdout)) - if (os.environ.get('OS_STDERR_NOCAPTURE') != 'True' and - os.environ.get('OS_STDERR_NOCAPTURE') != '1'): + if (os.environ.get('OS_STDERR_CAPTURE') == 'True' or + os.environ.get('OS_STDERR_CAPTURE') == '1'): stderr = self.useFixture(fixtures.StringStream('stderr')).stream self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr)) diff --git a/run_tests.sh b/run_tests.sh index a3ed978035bb..a34cab5a0f29 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -59,8 +59,6 @@ recreate_db=1 LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=C -OS_STDOUT_NOCAPTURE=False -OS_STDERR_NOCAPTURE=False for arg in "$@"; do process_option $arg diff --git a/tox.ini b/tox.ini index 4fa567518b18..a3e44630f8a5 100644 --- a/tox.ini +++ b/tox.ini @@ -6,9 +6,6 @@ setenv = VIRTUAL_ENV={envdir} LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=C - OS_STDOUT_NOCAPTURE=False - OS_STDERR_NOCAPTURE=False - deps = -r{toxinidir}/tools/pip-requires -r{toxinidir}/tools/test-requires commands = bash -c 'if [ ! -d ./.testrepository ] ; then testr init ; fi'