Merge "test cleanup: Use oslotest's CaptureOutput fixture"
This commit is contained in:
commit
e20d529dbf
@ -48,6 +48,7 @@ from oslo_utils import timeutils
|
||||
from oslo_versionedobjects import fixture as ovo_fixture
|
||||
from oslotest import mock_fixture
|
||||
from oslotest import moxstubout
|
||||
from oslotest import output
|
||||
from oslotest import timeout
|
||||
import six
|
||||
from six.moves import builtins
|
||||
@ -192,8 +193,7 @@ class TestCase(testtools.TestCase):
|
||||
self.useFixture(fixtures.TempHomeDir())
|
||||
self.useFixture(log_fixture.get_logging_handle_error_fixture())
|
||||
|
||||
self.output = nova_fixtures.OutputStreamCapture()
|
||||
self.useFixture(self.output)
|
||||
self.output = self.useFixture(output.CaptureOutput())
|
||||
|
||||
self.stdlog = nova_fixtures.StandardLogging()
|
||||
self.useFixture(self.stdlog)
|
||||
|
@ -204,34 +204,6 @@ class StandardLogging(fixtures.Fixture):
|
||||
self.logger._output.truncate(0)
|
||||
|
||||
|
||||
class OutputStreamCapture(fixtures.Fixture):
|
||||
"""Capture output streams during tests.
|
||||
|
||||
This fixture captures errant printing to stderr / stdout during
|
||||
the tests and lets us see those streams at the end of the test
|
||||
runs instead. Useful to see what was happening during failed
|
||||
tests.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(OutputStreamCapture, self).setUp()
|
||||
if os.environ.get('OS_STDOUT_CAPTURE') in _TRUE_VALUES:
|
||||
self.out = self.useFixture(fixtures.StringStream('stdout'))
|
||||
self.useFixture(
|
||||
fixtures.MonkeyPatch('sys.stdout', self.out.stream))
|
||||
if os.environ.get('OS_STDERR_CAPTURE') in _TRUE_VALUES:
|
||||
self.err = self.useFixture(fixtures.StringStream('stderr'))
|
||||
self.useFixture(
|
||||
fixtures.MonkeyPatch('sys.stderr', self.err.stream))
|
||||
|
||||
@property
|
||||
def stderr(self):
|
||||
return self.err._details["stderr"].as_text()
|
||||
|
||||
@property
|
||||
def stdout(self):
|
||||
return self.out._details["stdout"].as_text()
|
||||
|
||||
|
||||
class DatabasePoisonFixture(fixtures.Fixture):
|
||||
def setUp(self):
|
||||
super(DatabasePoisonFixture, self).setUp()
|
||||
|
@ -15,7 +15,6 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import sys
|
||||
|
||||
import fixtures as fx
|
||||
import futurist
|
||||
@ -26,6 +25,7 @@ from oslo_log import log as logging
|
||||
from oslo_utils.fixture import uuidsentinel as uuids
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
from oslotest import output
|
||||
import sqlalchemy
|
||||
import testtools
|
||||
|
||||
@ -89,25 +89,6 @@ class TestConfFixture(testtools.TestCase):
|
||||
self._test_override()
|
||||
|
||||
|
||||
class TestOutputStream(testtools.TestCase):
|
||||
"""Ensure Output Stream capture works as expected.
|
||||
|
||||
This has the added benefit of providing a code example of how you
|
||||
can manipulate the output stream in your own tests.
|
||||
"""
|
||||
def test_output(self):
|
||||
self.useFixture(fx.EnvironmentVariable('OS_STDOUT_CAPTURE', '1'))
|
||||
self.useFixture(fx.EnvironmentVariable('OS_STDERR_CAPTURE', '1'))
|
||||
|
||||
out = self.useFixture(fixtures.OutputStreamCapture())
|
||||
sys.stdout.write("foo")
|
||||
sys.stderr.write("bar")
|
||||
self.assertEqual("foo", out.stdout)
|
||||
self.assertEqual("bar", out.stderr)
|
||||
# TODO(sdague): nuke the out and err buffers so it doesn't
|
||||
# make it to testr
|
||||
|
||||
|
||||
class TestLogging(testtools.TestCase):
|
||||
def test_default_logging(self):
|
||||
stdlog = self.useFixture(fixtures.StandardLogging())
|
||||
@ -151,7 +132,7 @@ class TestOSAPIFixture(testtools.TestCase):
|
||||
@mock.patch('nova.objects.Service.create')
|
||||
def test_responds_to_version(self, mock_service_create, mock_get):
|
||||
"""Ensure the OSAPI server responds to calls sensibly."""
|
||||
self.useFixture(fixtures.OutputStreamCapture())
|
||||
self.useFixture(output.CaptureOutput())
|
||||
self.useFixture(fixtures.StandardLogging())
|
||||
self.useFixture(conf_fixture.ConfFixture())
|
||||
self.useFixture(fixtures.RPCFixture('nova.test'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user