Test Overview
This test demonstrates how an autouse fixture in pytest runs automatically before each test without being explicitly requested. It verifies that the fixture's setup code executes and affects the test environment.
This test demonstrates how an autouse fixture in pytest runs automatically before each test without being explicitly requested. It verifies that the fixture's setup code executes and affects the test environment.
import pytest @pytest.fixture(autouse=True) def setup_env(): print("Setup environment") return "env ready" def test_example(): assert True def test_check_env(): assert True
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | pytest starts test run | pytest test runner initialized | - | PASS |
| 2 | Autouse fixture 'setup_env' runs before 'test_example' | Prints 'Setup environment' to console | - | PASS |
| 3 | 'test_example' runs | Test executes with fixture setup done | assert True passes | PASS |
| 4 | Autouse fixture 'setup_env' runs before 'test_check_env' | Prints 'Setup environment' to console | - | PASS |
| 5 | 'test_check_env' runs | Test executes with fixture setup done | assert True passes | PASS |
| 6 | pytest finishes test run | All tests passed | - | PASS |