Testing output to streams
=========================

.. currentmodule:: testfixtures

In many situations, it's perfectly legitimate for output to be printed
to one of the standard streams. To aid with testing this kind of
output, TestFixtures provides the :class:`OutputCapture` helper.

This helper is a context manager that captures output sent to
``sys.stdout`` and ``sys.stderr`` and provides a
:meth:`~OutputCapture.compare` method to check that the output was as
expected.

Here's a simple example:

.. code-block:: python

  from testfixtures import OutputCapture
  import sys

  with OutputCapture() as output:
      # code under test
      print "Hello!"
      print >> sys.stderr, "Something bad happened!"

  output.compare('\n'.join([
      "Hello!",
      "Something bad happened!",
      ]))
