# Buffering test output

Buffer stdout and/or stderr during test execution, appending any output to the error reports of failed tests.

This allows you to use print for debugging in tests without making your test runs noisy.

This plugin implements `startTest()`, `stopTest()`, `setTestOutcome()`, `outcomeDetail()`, `beforeInteraction()` and `afterInteraction()` to manage capturing sys.stdout and/or sys.stderr into buffers, attaching the buffered output to test error report detail, and getting out of the way when other plugins want to talk to the user.

## Configuration [output-buffer]

always-on
  Default:

    False

  Type:

    boolean

stderr
  Default:

    False

  Type:

    boolean

stdout
  Default:

    True

  Type:

    boolean

### Sample configuration

The default configuration is equivalent to including the following in a `unittest.cfg` file.

    [output-buffer]
    always-on = False
    stderr = False
    stdout = True

## Command-line options

-B DEFAULT, --output-buffer DEFAULT

  Enable output buffer

## Plugin class reference: OutputBufferPlugin

class nose2.plugins.buffer.OutputBufferPlugin(*args, **kwargs)

  Buffer output during test execution

  afterInteraction(event)

    Start buffering again (does not clear buffers)

  beforeInteraction(event)

    Stop buffering so users can see stdout

  outcomeDetail(event)

    Add buffered output to event.extraDetail

  setTestOutcome(event)

    Attach buffer(s) to event.metadata

  startTest(event)

    Start buffering selected stream(s)

  stopTest(event)

    Stop buffering