56. Testing for Security and Resilience
Use tests to simulate bad input, missing files, and malformed data.
Example
import pytest, json
from pydo import safe_save
def test_invalid_task(monkeypatch):
with pytest.raises(ValueError):
from pydo import sanitize_task_input
sanitize_task_input("X" * 500)
def test_file_storage(tmp_path):
file_path = tmp_path / "tasks.json"
safe_save([{"task": "Secure Task"}])
assert file_path.exists()
✅ Lesson: Test for security failures, not just functional correctness.