Part 5 · 1 chapters · ~8 min
Tooling and Testing
uv for environments and lockfiles, pyproject.toml, ruff for linting and formatting, mypy and pyright, pytest with fixtures and parametrize, pytest-django and factory_boy, testcontainers for real Postgres, coverage, Hypothesis property tests, and pip-audit.
9
Tools and tests
code
# pyproject.toml
[project]
name = "ledger"
requires-python = ">=3.12"
dependencies = ["django>=5.1", "djangorestframework", "psycopg[binary]", "celery[redis]"]
[tool.ruff]
line-length = 110
[tool.mypy]
strict = true
# tests/test_fees.py
import pytest
from ledger.fees import fee
@pytest.mark.parametrize("amount,expected", [(100_000, 1_000), (5_000_000, 25_000)])
def test_fee(amount, expected): assert fee(amount) == expected
def test_rejects_zero():
with pytest.raises(ValueError): fee(0)
# property-based: Hypothesis
from hypothesis import given, strategies as st
@given(st.integers(min_value=1, max_value=10**12))
def test_fee_never_below_minimum(a): assert fee(a) >= 1_000THE MODERN PYTHON TOOLCHAIN
fast tools, mostly written in Rust
swipe the figure sideways, or tap expand for full screen
1/6
uv
uv resolves and installs dependencies in seconds, writes a lockfile (uv.lock), and manages Python versions.
packages, venvs, lockfiles, Python versionsuv sync, uv run