captured_stdin
Capture the input to sys.stdin:
with captured_stdin() as stdin:
stdin.write('hello\n')
stdin.seek(0)
# call test code that consumes from sys.stdin
captured = input()
self.assertEqual(captured, "hello")
def captured_stdin() - > context_manager
Capture the input to sys.stdin:
Returns
| Type | Description |
|---|---|
context_manager | A context manager that provides a file-like object (StringIO) to simulate and capture standard input |