Test Overview
This test checks if certain items are present or absent in a list using Python's in and not in operators. It verifies membership conditions with assertions.
This test checks if certain items are present or absent in a list using Python's in and not in operators. It verifies membership conditions with assertions.
import pytest def test_membership(): fruits = ['apple', 'banana', 'cherry'] # Check if 'banana' is in the list assert 'banana' in fruits # Check if 'orange' is not in the list assert 'orange' not in fruits
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Defines list fruits with ['apple', 'banana', 'cherry'] | List fruits created in memory | - | PASS |
| 3 | Checks if 'banana' is in fruits using assert 'banana' in fruits | Evaluates membership condition | 'banana' is found in fruits list | PASS |
| 4 | Checks if 'orange' is not in fruits using assert 'orange' not in fruits | Evaluates membership condition | 'orange' is not found in fruits list | PASS |
| 5 | Test ends successfully | All assertions passed | - | PASS |