-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.sh
63 lines (53 loc) · 1.6 KB
/
test.sh
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
#!/bin/bash
# Initialize variables to store passed and failed test cases
passed_cases=""
failed_cases=""
error_cases=""
# Function to run pytest and process the output
# Function to run pytest and process the output
run_test() {
# Run pytest with verbose and no capture, redirect stderr to stdout
pytest_output=$(python3 -m pytest -vv "$1" 2>&1)
# Print pytest output
echo "$pytest_output"
# Check if pytest output contains "failed"
if grep -q " FAILED " <<< "$pytest_output"; then
# Handle failed test case
echo "Test case $1 failed"
failed_cases+=" $1"
return 1
fi
if grep -q " ERROR " <<< "$pytest_output"; then
# Handle failed test case
echo "Test case $1 error"
error_cases+=" $1"
return 1
fi
# Handle successful test case
echo "Test case $1 passed"
passed_cases+=" $1"
return 0
}
# Main loop to run tests for each test case
for test_case in "$@"; do
run_test "$test_case"
done
# Display summary of test results
echo "Summary:"
echo "Passed test cases:${passed_cases}"
echo "Failed test cases:${failed_cases}"
echo "ERROR test cases:${error_cases}"
# Check if there are any failed cases
if [ -n "$failed_cases" ]; then
echo "Exist failed cases:${failed_cases//\//_}"
mv report/report.html "report/${failed_cases//\//_}.html"
exit 1
fi
# Check if there are any error cases
if [ -n "$error_cases" ]; then
echo "Exist error cases:${error_cases//\//_}"
mv report/report.html "report/${error_cases//\//_}.html"
exit 2
fi
rm -rf report/report.html
echo "No failed or error cases found"