-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathut_list_skipper.sh
More file actions
executable file
·64 lines (53 loc) · 2.74 KB
/
ut_list_skipper.sh
File metadata and controls
executable file
·64 lines (53 loc) · 2.74 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
#!/bin/bash
TEST_DIR="tests/"
PYTEST_RESULTS_FILE="pytest_results.log"
DEFAULT_INDENTATION="\ \ \ \ "
TEST_LIST_FILE="test_list.txt" # File containing the list of tests
# Function to process failed tests
process_failed_test() {
TEST_FILE=$1
TEST_FUNCTION=$2
echo "Processing failed test: $TEST_FUNCTION in $TEST_FILE"
# Check if "import pytest" is already added
if ! grep -q "import pytest" $TEST_FILE; then
# Check if there are any __future__ imports
if grep -q "from __future__ import" $TEST_FILE; then
# Insert 'import pytest' after the last __future__ import
awk '/from __future__ import/ {print; last_line=NR; next} NR==last_line+1 {print "import pytest\n"$0; next} {print}' $TEST_FILE > temp_file && mv temp_file $TEST_FILE
else
# Add 'import pytest' at the top of the file
sed -i '1s/^/import pytest\n/' $TEST_FILE
fi
fi
# Add the skip decorator above the failing test
sed -i "/def ${TEST_FUNCTION}/i ${DEFAULT_INDENTATION}@pytest.mark.skip(reason=\"UT compatibility skip\")" $TEST_FILE
}
# Loop through each test in the list
while read -r test_name; do
echo "Running pytest for: $test_name"
RUN_SLOW=1 pytest --verbose ${test_name} -p no:cacheprovider | tee $PYTEST_RESULTS_FILE
# Check if the test failed
if grep -q 'FAILED' $PYTEST_RESULTS_FILE; then
#TEST_FILE=$(grep 'FAILED' $PYTEST_RESULTS_FILE | awk -F "::" '{print $1}')
#TEST_FUNCTION=$(grep 'FAILED' $PYTEST_RESULTS_FILE | awk -F "::" '{print $3}' | awk '{print $1}')
#process_failed_test $TEST_FILE $TEST_FUNCTION
TEST_FILE=$(grep 'FAILED' pytest_results.log | sed 's/.* \(.*::\)/\1/' | awk -F "::" '{print $1}' | sort | uniq
)
TEST_FUNCTION=$(grep 'FAILED' pytest_results.log | sed 's/.* \(.*::\)/\1/' | awk -F "::" '{print $3}' | cut -d " " -f1 | sort | uniq
)
echo "Processing failed test: $TEST_FUNCTION in $TEST_FILE"
# Check if "import pytest" is already added
if ! grep -q "import pytest" $TEST_FILE; then
# Check if there are any __future__ imports
if grep -q "from __future__ import" $TEST_FILE; then
# Insert 'import pytest' after the last __future__ import
awk '/from __future__ import/ {print; last_line=NR; next} NR==last_line+1 {print "import pytest\n"$0; next} {print}' $TEST_FILE > temp_file && mv temp_file $TEST_FILE
else
# Add 'import pytest' at the top of the file
sed -i '1s/^/import pytest\n/' $TEST_FILE
fi
fi
# Add the skip decorator above the failing test
sed -i "/def ${TEST_FUNCTION}/i ${DEFAULT_INDENTATION}@pytest.mark.skip(reason=\"UT compatibility skip\")" $TEST_FILE
fi
done < "$TEST_LIST_FILE"