[pytest] # Pytest配置文件 # 测试发现 python_files = test_*.py python_classes = Test* python_functions = test_* # 测试路径 testpaths = tests # 输出选项 addopts = # 详细输出 -v # 显示本地变量(失败时) -l # 显示print输出 -s # 显示测试覆盖率 --cov=app --cov-report=html --cov-report=term-missing # 生成HTML报告 --html=test_reports/pytest_report.html --self-contained-html # 生成XML报告(JUnit格式) --junitxml=test_reports/junit.xml # 显示最慢的10个测试 --durations=10 # 颜色输出 --color=yes # 警告设置 -W ignore::DeprecationWarning # 并行执行(需要pytest-xdist) # -n auto # 重试失败的测试(需要pytest-rerunfailures) # --reruns=2 # --reruns-delay=1 # 标记定义 markers = smoke: 冒烟测试(快速验证基本功能) regression: 回归测试(完整功能测试) integration: 集成测试(需要数据库/外部服务) unit: 单元测试(独立测试) slow: 慢速测试(执行时间较长) security: 安全测试 performance: 性能测试 api: API测试 # 覆盖率配置 [coverage:run] source = app omit = */tests/* */test_*.py */__pycache__/* */site-packages/* */venv/* */migrations/* */config.py [coverage:report] # 覆盖率目标 precision = 2 show_missing = True skip_covered = False # 最低覆盖率要求 fail_under = 70.0 [coverage:html] directory = test_reports/htmlcov [coverage:xml] output = test_reports/coverage.xml