def captured_stderr():
return captured_output("<STR_LIT>")<EOL>
Capture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello\\n")