new_contents: import sys
  from contextlib import contextmanager
  
  try:
      from StringIO import StringIO
  except ImportError:
      from io import StringIO
  
  
  @contextmanager
  def captured_output():
      new_out, new_err = StringIO(), StringIO()
      old_out, old_err = sys.stdout, sys.stderr
      try:
          sys.stdout, sys.stderr = new_out, new_err
          yield sys.stdout, sys.stderr
      finally:
          sys.stdout, sys.stderr = old_out, old_err
  
subject: add context manager for capturing stdout/stderr