|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -e # 可选:出错立即退出,可去掉如果想继续执行后续测试 |
| 3 | + |
1 | 4 | # 获取当前工作目录 |
2 | 5 | home=$PWD |
3 | 6 |
|
4 | | -# 运行 api 测试脚本,并获取退出码 |
| 7 | +# ===== 1. 运行 API 测试 ===== |
5 | 8 | cd test_apis |
6 | 9 | bash ./run.sh |
7 | 10 | api=$? |
8 | | -echo ${api} |
| 11 | +echo "api exit code: ${api}" |
9 | 12 | cd $home |
10 | 13 |
|
11 | | -# 运行 examples 测试脚本,并获取退出码 |
| 14 | +# ===== 2. 运行 Model/Example 测试 ===== |
12 | 15 | cd test_models |
13 | 16 | bash ./run.sh |
14 | 17 | example=$? |
15 | | -echo ${example} |
| 18 | +echo "example exit code: ${example}" |
16 | 19 | 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. 输出结果汇总 ===== |
18 | 29 | echo "=============== result =================" |
19 | 30 | 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}" |
26 | 41 | echo "------------------------" |
27 | | - done |
28 | | - echo "success!" |
| 42 | + done |
| 43 | + echo -e "\033[32msuccess!\033[0m" |
29 | 44 | 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" |
38 | 54 | fi |
39 | | -echo `expr ${api} + ${example}` |
40 | | -exit `expr ${api} + ${example}` |
| 55 | + |
| 56 | +echo "Total exit code: ${total}" |
| 57 | +exit ${total} |
0 commit comments