Skip to content

Commit 68c2c0d

Browse files
committed
support pytest
Signed-off-by: chensuyue <[email protected]>
1 parent 7499cd8 commit 68c2c0d

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

.azure-pipelines/scripts/ut/3x/run_3x_pt.sh

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,43 @@ pip list
1111

1212
export COVERAGE_RCFILE=/neural-compressor/.azure-pipelines/scripts/ut/3x/coverage.3x_pt
1313
inc_path=$(python -c 'import neural_compressor; print(neural_compressor.__path__[0])')
14-
cd /neural-compressor/test || exit 1
15-
find ./3x/torch/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run.sh
16-
find ./3x/common/* -name "test*.py" | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'>> run.sh
14+
cd /neural-compressor/test/3x || exit 1
15+
grep -lrv "import pytest" --include="test*.py" ./torch | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'> run_unittest.sh
16+
grep -lrv "import pytest" --include="test*.py" ./common | sed 's,\.\/,coverage run --source='"${inc_path}"' --append ,g' | sed 's/$/ --verbose/'>> run_unittest.sh
17+
grep -lr "import pytest" --include="test*.py" ./torch | sed 's,\.\/,coverage run --source='"${inc_path}"' --append pytest -m ,g' | sed 's/$/ --verbose/'> run_pytest.sh
18+
grep -lr "import pytest" --include="test*.py" ./common | sed 's,\.\/,coverage run --source='"${inc_path}"' --append pytest -m ,g' | sed 's/$/ --verbose/'>> run_pytest.sh
1719

1820
LOG_DIR=/neural-compressor/log_dir
1921
mkdir -p ${LOG_DIR}
2022
ut_log_name=${LOG_DIR}/ut_3x_pt.log
2123

22-
echo "cat run.sh..."
23-
sort run.sh -o run.sh
24-
cat run.sh | tee ${ut_log_name}
25-
echo "------UT start-------"
26-
bash -x run.sh 2>&1 | tee -a ${ut_log_name}
27-
cp .coverage ${LOG_DIR}/.coverage
24+
echo "cat run_unittest.sh..."
25+
sort run_unittest.sh -o run_unittest.sh
26+
cat run_unittest.sh | tee ${ut_log_name}
27+
echo "------unittest start-------"
28+
bash -x run_unittest.sh 2>&1 | tee -a ${ut_log_name}
29+
echo "------unittest end -------"
30+
31+
echo "cat run_pytest.sh..."
32+
sort run_pytest.sh -o run_pytest.sh
33+
cat run_pytest.sh | tee -a ${ut_log_name}
34+
echo "------pytest start-------"
35+
bash -x run_pytest.sh 2>&1 | tee -a ${ut_log_name}
36+
echo "------pytest end -------"
2837

29-
echo "------UT end -------"
38+
cp .coverage ${LOG_DIR}/.coverage
3039

40+
# check unittest issue
3141
if [ $(grep -c "FAILED" ${ut_log_name}) != 0 ] || [ $(grep -c "core dumped" ${ut_log_name}) != 0 ] \
3242
|| [ $(grep -c "ModuleNotFoundError:" ${ut_log_name}) != 0 ] || [ $(grep -c "ImportError:" ${ut_log_name}) != 0 ] || [ $(grep -c "OK" ${ut_log_name}) == 0 ];then
3343
echo "Find errors in UT test, please check the output..."
3444
exit 1
3545
fi
46+
47+
# check pytest issue
48+
if [ $(grep -c 'failed,' ${ut_log_name}) != 0 ] || [ $(grep -c 'passed,' ${ut_log_name}) ]; then
49+
echo "Find errors in UT test, please check the output..."
50+
exit 1
51+
fi
52+
3653
echo "UT finished successfully! "

0 commit comments

Comments
 (0)