1. pytest
# tests/test_math.py
def test_add():
assert 1 + 1 == 2
pip install pytest
pytest
2. ruff + black
ruff 一体化 linter;black 约定式格式化。
pip install ruff black
ruff check .
black .
3. mypy
pip install mypy
mypy .
4. pyproject.toml(节选)
[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.12"
[tool.ruff]
line-length = 100
[tool.black]
line-length = 100
📋 本章要点
pytest 保证回归;ruff/black 统一风格;mypy 捕获类型错误;配置集中在 pyproject.toml。
评论加载中...