Files
FastDeploy/scripts/coverage_run.sh
kesmeey d81341b9b3 [CI]【Hackathon 9th Sprint No.14】功能模块 fastdeploy/rl/rollout_model.py 单测补充 (#5552)
* Add rollout model unit tests

* test: update rl rollout_model tests

* test: fix cache_type_branches unsupported platform case

* test: fix rl rollout_model test indent

* Delete tests/spec_decode/test_mtp_proposer.py

* chore: format test_rollout_model

* chore: translate rollout test comments to English

* test: guard rollout_model import by disabling auto registry

* chore: reorder imports in rl rollout test

* test: isolate env for RL rollout tests

* style: format rollout RL tests with black

* update

* test: remove RL rollout unit tests causing collection issues

* test: add lightweight rollout_model RL unit tests

* fix(coverage): filter test file paths and handle collection failures

- Only extract real test file paths (tests/.../test_*.py) from pytest collect output

- Filter out ERROR/collecting prefixes to prevent garbage in failed_tests.log

- Add proper error handling for pytest collection failures

- Exit early if no test files can be extracted

- Preserve collection error output for debugging

* update

* style: fix code style issues in test_rollout_model.py

- Remove unused 'os' import

- Remove trailing blank lines

---------

Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
2025-12-18 10:57:53 +08:00

64 lines
2.2 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
tests_path="$DIR/../tests/"
export PYTEST_INI="$DIR/../tests/cov_pytest.ini"
run_path=$( realpath "$DIR/../")
export COVERAGE_FILE=${COVERAGE_FILE:-$DIR/../coveragedata/.coverage}
export COVERAGE_RCFILE=${COVERAGE_RCFILE:-$DIR/../scripts/.coveragerc}
failed_tests_file="failed_tests.log"
> "$failed_tests_file"
##################################
# 执行 pytest每个文件单独跑
# 使用 pytest 的 --collect-only 输出,并从每行中提取真正的测试文件路径(形如 tests/.../test_*.py
# 注意pytest 在收集失败时会输出形如 "ERROR tests/xxx/test_xxx.py::test_xxx ..." 的行,
# 为了避免把前缀 "ERROR"/"FAILED"/"collecting" 等误当成文件名,这里只保留行中出现的
# "tests/.../test_*.py" 这一段,其他前后内容直接丢弃。
TEST_FILES=$(
python -m pytest --collect-only -q -c "${PYTEST_INI}" "${tests_path}" --rootdir="${run_path}" --disable-warnings 2>&1 \
| grep -E 'tests/.+\/test_.*\.py' \
| sed -E 's@.*(tests/[^: ]*test_[^: ]*\.py).*@\1@' \
| sort -u
)
failed_pytest=0
success_pytest=0
for file in $TEST_FILES; do
echo "Running pytest file: $file"
python -m coverage run -m pytest -c ${PYTEST_INI} "$file" -vv -s
status=$?
if [ "$status" -ne 0 ]; then
echo "$file" >> "$failed_tests_file"
failed_pytest=$((failed_pytest+1))
else
success_pytest=$((success_pytest+1))
fi
ps -ef | grep "${FD_CACHE_QUEUE_PORT}" | grep -v grep | awk '{print $2}' | xargs -r kill -9
ps -ef | grep "${FD_ENGINE_QUEUE_PORT}" | grep -v grep | awk '{print $2}' | xargs -r kill -9
done
##################################
# 汇总结果
##################################
echo "===================================="
echo "Pytest total: $((failed_pytest + success_pytest))"
echo "Pytest successful: $success_pytest"
echo "Pytest failed: $failed_pytest"
echo "Special tests total: ${#special_tests[@]}"
echo "Special tests successful: $success_special"
if [ "$failed_pytest" -ne 0 ]; then
echo "Failed test cases are listed in $failed_tests_file"
cat "$failed_tests_file"
exit 8
fi
echo "All tests passed!"