Test Overview
This test checks if two variables point to the exact same object in memory using is and is not operators. It verifies identity, not just equality.
This test checks if two variables point to the exact same object in memory using is and is not operators. It verifies identity, not just equality.
import pytest def test_identity(): a = [1, 2, 3] b = a c = [1, 2, 3] # Check that a and b are the same object assert a is b # Check that a and c are not the same object assert a is not c # Check that a and c have equal content assert a == c
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | pytest test runner initialized | - | PASS |
| 2 | Assign list [1, 2, 3] to variable a | Variable a points to a list object in memory | - | PASS |
| 3 | Assign variable b to reference the same object as a | Variables a and b point to the same list object | - | PASS |
| 4 | Assign variable c to a new list [1, 2, 3] | Variable c points to a different list object with same content | - | PASS |
| 5 | Assert that a is b (identity check) | a and b reference the same object | assert a is b | PASS |
| 6 | Assert that a is not c (identity check) | a and c reference different objects | assert a is not c | PASS |
| 7 | Assert that a == c (equality check) | a and c have equal content | assert a == c | PASS |
| 8 | Test ends | All assertions passed | - | PASS |