Test Overview
This test uses the pytest fixture request object to access the name of the test function dynamically. It verifies that the fixture correctly provides the test function's name during execution.
This test uses the pytest fixture request object to access the name of the test function dynamically. It verifies that the fixture correctly provides the test function's name during execution.
import pytest @pytest.fixture def fixture_with_request(request): # Access the name of the test function using request return request.function.__name__ def test_example(fixture_with_request): # Assert that the fixture returns the current test function name assert fixture_with_request == "test_example"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initializes | - | PASS |
| 2 | pytest collects test_example function | Test function test_example is ready to run | - | PASS |
| 3 | pytest calls fixture_with_request fixture with request object | Fixture receives request object containing test context | request.function.__name__ is 'test_example' | PASS |
| 4 | Fixture returns the test function name 'test_example' | Fixture output is 'test_example' | - | PASS |
| 5 | test_example function runs with fixture_with_request value | test_example receives 'test_example' from fixture | assert fixture_with_request == 'test_example' | PASS |
| 6 | Test completes successfully | Test passed with no errors | - | PASS |