-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·90 lines (81 loc) · 2.25 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·90 lines (81 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# 运行测试脚本
set -e
echo "========================================"
echo "Python3项目测试运行"
echo "========================================"
# 检查是否在虚拟环境中
if [[ "$VIRTUAL_ENV" == "" ]]; then
echo "⚠️ 不在虚拟环境中"
if [ -d "venv" ]; then
echo "激活虚拟环境..."
source venv/bin/activate
else
echo "❌ 错误: 未找到虚拟环境"
echo "请先运行: ./setup_venv.sh"
exit 1
fi
fi
echo "Python版本: $(python --version)"
echo "工作目录: $(pwd)"
echo ""
# 检查pytest
if ! python -c "import pytest" 2>/dev/null; then
echo "安装pytest..."
pip install pytest pytest-cov
fi
# 选择测试模式
echo "选择测试模式:"
echo " 1. 运行所有测试"
echo " 2. 运行单元测试"
echo " 3. 运行特定测试文件"
echo " 4. 运行测试并生成覆盖率报告"
echo " 5. 退出"
read -p "请选择 (1-5): " choice
case $choice in
1)
echo "运行所有测试..."
python -m pytest tests/ -v
;;
2)
echo "运行单元测试..."
python -m pytest tests/unit/ -v
;;
3)
echo "可用测试文件:"
find tests/ -name "test_*.py" | sort
echo ""
read -p "请输入测试文件路径: " test_file
if [ -f "$test_file" ]; then
python -m pytest "$test_file" -v
else
echo "❌ 文件不存在: $test_file"
exit 1
fi
;;
4)
echo "运行测试并生成覆盖率报告..."
if python -c "import pytest_cov" 2>/dev/null; then
python -m pytest tests/ -v --cov=. --cov-report=term-missing --cov-report=html
echo ""
echo "✅ 覆盖率报告已生成"
echo "打开: file://$(pwd)/htmlcov/index.html"
else
echo "安装pytest-cov..."
pip install pytest-cov
python -m pytest tests/ -v --cov=. --cov-report=term-missing --cov-report=html
fi
;;
5)
echo "退出"
exit 0
;;
*)
echo "无效选择"
exit 1
;;
esac
echo ""
echo "========================================"
echo "测试完成!"
echo "========================================"