Capture the output of sys.stdout: with captured_stdout() as stdout: print("hello") self.assertEqual(stdout.getvalue(), "hello\\n")
()
| 816 | setattr(sys, stream_name, orig_stdout) |
| 817 | |
| 818 | def captured_stdout(): |
| 819 | """Capture the output of sys.stdout: |
| 820 | |
| 821 | with captured_stdout() as stdout: |
| 822 | print("hello") |
| 823 | self.assertEqual(stdout.getvalue(), "hello\\n") |
| 824 | """ |
| 825 | return captured_output("stdout") |
| 826 | |
| 827 | def captured_stderr(): |
| 828 | """Capture the output of sys.stderr: |