Capture the output of sys.stderr: with captured_stderr() as stderr: print("hello", file=sys.stderr) self.assertEqual(stderr.getvalue(), "hello\\n")
()
| 825 | return captured_output("stdout") |
| 826 | |
| 827 | def captured_stderr(): |
| 828 | """Capture the output of sys.stderr: |
| 829 | |
| 830 | with captured_stderr() as stderr: |
| 831 | print("hello", file=sys.stderr) |
| 832 | self.assertEqual(stderr.getvalue(), "hello\\n") |
| 833 | """ |
| 834 | return captured_output("stderr") |
| 835 | |
| 836 | def captured_stdin(): |
| 837 | """Capture the input to sys.stdin: |