import sys import pytest import cipy._io def test_capture_cout() -> None: with cipy._io.capture_stdout() as out: print("Hello, World") sys.stdout.flush() assert out.getvalue() == "Hello, World\n" def test_capture_cerr() -> None: with cipy._io.capture_stderr() as out: print("Hello, World", file=sys.stderr) sys.stderr.flush() assert out.getvalue() == "Hello, World\n" def test_capture_expires_scope() -> None: with cipy._io.capture_stdout() as out: pass with pytest.raises(ValueError): out.read()