Complete the code to capture printed output using capfd fixture.
def test_print_output([1]): print("Hello, world!") out, err = capfd.readouterr() assert out == "Hello, world!\n"
The capfd fixture captures output to file descriptors like stdout and stderr.
Complete the code to capture and check stderr output using capfd.
def test_error_output(capfd): import sys print("Error message", file=[1]) out, err = capfd.readouterr() assert err == "Error message\n"
To capture error output, print to sys.stderr.
Fix the error in the code to correctly capture output using capfd.
def test_output([1]): print("Test") out, err = capfd.readouterr() assert out == "Test\n"
The function argument must be capfd to use its readouterr() method.
Fill both blanks to capture output and check it after printing.
def test_multiple_prints([1]): print("First line") print("Second line") out, err = [2].readouterr() assert out == "First line\nSecond line\n"
Both blanks must be capfd to capture and read output correctly.
Fill all three blanks to capture output, print error, and assert both outputs.
def test_output_and_error([1]): print("Output line") import sys print("Error line", file=sys.stderr) out, err = [2].readouterr() assert out == "Output line\n" assert err == [3]
The fixture capfd captures both stdout and stderr. The error output string must match exactly.
