最简用例
最简用例
def add(a, b):
return a + b
def test_add():
assert add(1, 1) == 2运行方式
运行方式
pip install pytest
pytest -q
pytest tests/test_math.py::test_addpytest 能直接运行 unittest 风格用例,存量项目可渐进迁移。
pytest 用普通函数加 assert 写用例:文件名匹配 test_*.py、函数匹配 test_* 自动发现;断言内省、夹具与参数化内置,插件覆盖并行、重试、覆盖率等场景。
def add(a, b):
return a + b
def test_add():
assert add(1, 1) == 2pip install pytest
pytest -q
pytest tests/test_math.py::test_add