-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathut_skipper.sh
More file actions
executable file
·42 lines (29 loc) · 1.47 KB
/
ut_skipper.sh
File metadata and controls
executable file
·42 lines (29 loc) · 1.47 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
#!/bin/bash
# Define the directory containing the test files
TEST_DIR="tests/"
# File to store pytest results
PYTEST_RESULTS_FILE="pytest_results.log"
DEFAULT_INDENTATION="\ \ \ \ "
# Run pytest with --verbose and --no-cache, saving output to a file
RUN_SLOW=1 pytest --verbose $TEST_DIR -p no:cacheprovider | tee $PYTEST_RESULTS_FILE
# Process each failed test from the pytest output
grep 'FAILED' $PYTEST_RESULTS_FILE | while read -r line; do
# Extract the test file and test function from the line
TEST_FILE=$(echo $line | awk -F "::" '{print $1}')
TEST_FUNCTION=$(echo $line | awk -F "::" '{print $3}' | awk '{print $1}')
echo $TEST_FILE
echo $TEST_FUNCTION
# 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 with correct indentation above the failing test
sed -i "/def ${TEST_FUNCTION}/i ${DEFAULT_INDENTATION}@pytest.mark.skip(reason=\"UT compatibility skip\")" $TEST_FILE
done