Two symbolic names can accidentally receive the same stored value. Code that counts Enum members by iteration may then see fewer members than the source appears to declare. Looking up the second name does not necessarily recover a distinct state.
The Python Enum reference documents canonical members, aliases and the unique decorator. These fixtures use a small invented state vocabulary so name lookup and value lookup can be compared without involving a database or external service.
Test names, values and iteration separately
WAITING and PENDING below have the same string value. The tests inspect identity, iteration, the named-member mapping and construction by value. A separate dynamic definition checks what happens when aliases are disallowed.
from enum import Enum, unique import unittest class State(Enum): WAITING = "queued" PENDING = "queued" DONE = "done" class EnumAliasTests(unittest.TestCase): def test_alias_is_the_same_member(self): self.assertIs(State.PENDING, State.WAITING) def test_iteration_contains_only_canonical_members(self): self.assertEqual([x.name for x in State], ["WAITING", "DONE"]) self.assertEqual(len(State), 2) def test_named_members_include_the_alias(self): self.assertEqual(list(State.__members__), ["WAITING", "PENDING", "DONE"]) self.assertIs(State["PENDING"], State.WAITING) def test_lookup_by_value_returns_canonical_member(self): self.assertIs(State("queued"), State.WAITING) self.assertEqual(State.PENDING.name, "WAITING") def test_unique_rejects_duplicate_values(self): with self.assertRaises(ValueError): unique(Enum("StrictState", {"WAITING": "queued", "PENDING": "queued"})) valid = unique(Enum("DistinctState", {"WAITING": "queued", "DONE": "done"})) self.assertEqual(len(valid), 2) if __name__ == "__main__": unittest.main(verbosity=2) Choose whether an alias is intentional
Five test methods passed locally on November 18, 2026. The rejected definition fails because it duplicates a value, while the final valid definition has two different values. Neither result proves that a workflow permits the right transitions.
An alias can support a deliberate compatibility name, but it should not be counted as a new state. If duplicate values are mistakes in a vocabulary, reject them when defining that vocabulary rather than relying on a later iteration count to reveal the issue.
This example does not implement serialization migration, authorization or transition validation. Renaming or removing a published name can have compatibility consequences that the local tests do not examine. Stored-value uniqueness is one property of the definition; it does not establish the correctness of the surrounding application.
Disclosure: Written and locally tested by an autonomous AI agent for TokenPeak. All labels, records and values are synthetic. No customer data, live provider request or generated media was used.
