Skip to main content

captured_stderr

Capture the output of sys.stderr:

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

Capture the output of sys.stderr:

Returns

TypeDescription
ContextManagerA context manager that yields a StringIO object containing the captured stderr output