Skip to content

Commit d71cdcf

Browse files
authored
Improve test execution and result reporting
Refactor test result handling and output summary.
1 parent c6e06ea commit d71cdcf

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

models/PaddleScience/CI/run.sh

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -e # 可选:出错立即退出,可去掉如果想继续执行后续测试
3+
14
# 获取当前工作目录
25
home=$PWD
36

4-
# 运行 api 测试脚本,并获取退出码
7+
# ===== 1. 运行 API 测试 =====
58
cd test_apis
69
bash ./run.sh
710
api=$?
8-
echo ${api}
11+
echo "api exit code: ${api}"
912
cd $home
1013

11-
# 运行 examples 测试脚本,并获取退出码
14+
# ===== 2. 运行 Model/Example 测试 =====
1215
cd test_models
1316
bash ./run.sh
1417
example=$?
15-
echo ${example}
18+
echo "example exit code: ${example}"
1619
cd $home
17-
# 输出测试结果
20+
21+
# ===== 3. 运行 pytest 测试 =====
22+
echo "running pytest..."
23+
pytest_log="pytest_result.txt"
24+
python -m pytest ../test --maxfail=1 --disable-warnings -q | tee ${pytest_log}
25+
pytest_ret=${PIPESTATUS[0]}
26+
echo "pytest exit code: ${pytest_ret}"
27+
28+
# ===== 4. 输出结果汇总 =====
1829
echo "=============== result ================="
1930
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
20-
if [ `expr ${api} + ${example}` -eq 0 ]; then
21-
# 如果两个测试脚本的退出码之和为 0,则说明测试全部通过,输出正确结果并退出程序
22-
result=`find . -name "result.txt"`
23-
for file in ${result}
24-
do
25-
cat ${file}
31+
32+
total=$((api + example + pytest_ret))
33+
34+
if [ ${total} -eq 0 ]; then
35+
# 全部通过
36+
echo "All tests passed!"
37+
result_files=$(find . -name "result.txt" -o -name "pytest_result.txt")
38+
for file in ${result_files}; do
39+
echo "------ ${file} ------"
40+
cat "${file}"
2641
echo "------------------------"
27-
done
28-
echo "success!"
42+
done
43+
echo -e "\033[32msuccess!\033[0m"
2944
else
30-
# 如果两个测试脚本的退出码之和不为 0,则说明有测试未通过,输出错误结果并退出程序
31-
result=`find $home/ -name "result.txt"`
32-
for file in ${result}
33-
do
34-
cat ${file}
35-
echo "--------------------------"
36-
done
37-
echo "error!"
45+
# 有失败
46+
echo "Some tests failed!"
47+
result_files=$(find . -name "result.txt" -o -name "pytest_result.txt")
48+
for file in ${result_files}; do
49+
echo "------ ${file} ------"
50+
cat "${file}"
51+
echo "------------------------"
52+
done
53+
echo -e "\033[31merror!\033[0m"
3854
fi
39-
echo `expr ${api} + ${example}`
40-
exit `expr ${api} + ${example}`
55+
56+
echo "Total exit code: ${total}"
57+
exit ${total}

0 commit comments

Comments
 (0)