Test Overview
This test checks if the function prints the expected message to the console. It uses capsys to capture the printed output and verifies it matches the expected string.
This test checks if the function prints the expected message to the console. It uses capsys to capture the printed output and verifies it matches the expected string.
import pytest def greet(name): print(f"Hello, {name}!") def test_greet_output(capsys): greet("Alice") captured = capsys.readouterr() assert captured.out == "Hello, Alice!\n"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Calls greet("Alice") function | Function prints 'Hello, Alice!' to standard output | - | PASS |
| 3 | capsys.readouterr() captures printed output | Captured output contains 'Hello, Alice!\n' | - | PASS |
| 4 | Assert captured.out equals 'Hello, Alice!\n' | Captured output matches expected string | assert captured.out == 'Hello, Alice!\n' | PASS |
| 5 | Test ends | Test passed with no errors | - | PASS |