From 0772d24cabc0917e85e9cfbc6e788800c237a2c0 Mon Sep 17 00:00:00 2001 From: Claude BM Date: Tue, 21 Apr 2026 07:13:15 +0000 Subject: [PATCH] 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) --- ci-runner.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ci-runner.sh b/ci-runner.sh index 932d10a..d82d15e 100755 --- a/ci-runner.sh +++ b/ci-runner.sh @@ -73,7 +73,12 @@ if [ ! -f "$PYTHON" ]; then PYTHON="python3" 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=$? 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) 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" if [ "$FAIL_COUNT" != "0" ] && [ "$FAIL_COUNT" != "" ]; then