Complete worked example
python
import copy
import pytest
def select_roles(records, minimum):
if minimum < 0:
raise ValueError("minimum must be nonnegative")
return [row for row in records if row["years"] >= minimum]
def test_selection_preserves_input():
records = [{"id": "junior", "years": 1}, {"id": "senior", "years": 3}]
before = copy.deepcopy(records)
assert [r["id"] for r in select_roles(records, 2)] == ["senior"]
assert records == before
def test_negative_minimum_rejected():
with pytest.raises(ValueError, match="nonnegative"):
select_roles([], -1)- Reasoning
- The worked module selects records into a new list. One test checks the selected ID and unchanged input; another checks the invalid threshold. Literal expected IDs avoid repeating the comprehension as the oracle. The tests use only synthetic records with an explicit experience field. Run collection, then the suite, and read the phase outcomes. The playground’s syntax check only compiles source; it cannot replace these assertions. Likewise a typing completion record is not the same thing as having executed the regression suite.