Fix pytest-timeout detection and catch collection errors
--timeout flag caused pytest to fail silently on branches without pytest-timeout installed. Now checks for the package first. Also detects when pytest exits non-zero with 0 results (collection error) and properly reports it as a failure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
11b11ea8de
commit
0772d24cab
13
ci-runner.sh
13
ci-runner.sh
@ -73,7 +73,12 @@ if [ ! -f "$PYTHON" ]; then
|
|||||||
PYTHON="python3"
|
PYTHON="python3"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TEST_OUTPUT=$($PYTHON -m pytest "$WORKTREE/backend/tests/" --tb=line -q --timeout="$TIMEOUT" 2>&1)
|
TIMEOUT_FLAG=""
|
||||||
|
if $PYTHON -c "import pytest_timeout" 2>/dev/null; then
|
||||||
|
TIMEOUT_FLAG="--timeout=$TIMEOUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
TEST_OUTPUT=$($PYTHON -m pytest "$WORKTREE/backend/tests/" --tb=line -q $TIMEOUT_FLAG 2>&1)
|
||||||
TEST_EXIT=$?
|
TEST_EXIT=$?
|
||||||
|
|
||||||
PASS_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ passed' | grep -oP '\d+' || echo 0)
|
PASS_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ passed' | grep -oP '\d+' || echo 0)
|
||||||
@ -81,6 +86,12 @@ FAIL_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ failed' | grep -oP '\d+' || ech
|
|||||||
SKIP_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ skipped' | grep -oP '\d+' || echo 0)
|
SKIP_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ skipped' | grep -oP '\d+' || echo 0)
|
||||||
ERROR_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ error' | grep -oP '\d+' || echo 0)
|
ERROR_COUNT=$(echo "$TEST_OUTPUT" | grep -oP '\d+ error' | grep -oP '\d+' || echo 0)
|
||||||
|
|
||||||
|
if [ "$TEST_EXIT" -ne 0 ] && [ "$PASS_COUNT" = "0" ] && [ "$FAIL_COUNT" = "0" ]; then
|
||||||
|
ERROR_COUNT=1
|
||||||
|
echo "WARNING: pytest exited with code $TEST_EXIT but reported no results — likely a collection error"
|
||||||
|
echo "$TEST_OUTPUT" | tail -5
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Tests: $PASS_COUNT passed, $FAIL_COUNT failed, $SKIP_COUNT skipped, $ERROR_COUNT errors"
|
echo "Tests: $PASS_COUNT passed, $FAIL_COUNT failed, $SKIP_COUNT skipped, $ERROR_COUNT errors"
|
||||||
|
|
||||||
if [ "$FAIL_COUNT" != "0" ] && [ "$FAIL_COUNT" != "" ]; then
|
if [ "$FAIL_COUNT" != "0" ] && [ "$FAIL_COUNT" != "" ]; then
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user