Skip to content

Instantly share code, notes, and snippets.

@jangia
Created March 18, 2024 17:25
Show Gist options
  • Save jangia/660af2c3417c40d7c55229a0b54217b5 to your computer and use it in GitHub Desktop.
Save jangia/660af2c3417c40d7c55229a0b54217b5 to your computer and use it in GitHub Desktop.
Testing behavior, not implementation details – In-Memory Store
# behavior/store.py
class TaskStoreInMemory(TaskStore):
def __init__(self):
self._tasks = []
def add_task(self, task: Task) -> None:
self._tasks.append(task)
def list_tasks(self) -> list[Task]:
return self._tasks
# behavior/tests.py
@pytest.fixture
def store_() -> TaskStoreInMemory:
return TaskStoreInMemory()
def test_added_task_listed_(store_: TaskStoreInMemory):
task = Task(title="Do the dishes", status=TaskStatus.OPEN)
store_.add_task(task)
assert store_.list_tasks() == [task]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment