Skip to content

Commit e0fc558

Browse files
committed
Improve test-local pytest phase reporting
1 parent 92fce34 commit e0fc558

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

scripts/test-local.sh

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,26 @@ check_dependencies() {
312312
print_message $GREEN "All required dependencies are installed!"
313313
}
314314

315+
run_pytest_phase() {
316+
local phase_name="$1"
317+
shift
318+
319+
print_message $BLUE "Running $phase_name: $(printf '%q ' "$@")"
320+
321+
set +e
322+
"$@"
323+
local phase_exit_code=$?
324+
set -e
325+
326+
if [ "$phase_exit_code" -eq 0 ]; then
327+
print_message $GREEN "$phase_name passed"
328+
else
329+
print_message $RED "$phase_name failed with exit code $phase_exit_code"
330+
fi
331+
332+
return "$phase_exit_code"
333+
}
334+
315335
# MongoDB functions
316336
start_mongodb() {
317337
print_message $YELLOW "Starting MongoDB container..."
@@ -613,23 +633,36 @@ EOF
613633
PYTEST_ARGS+=(--cov=cachier --cov-report="$COVERAGE_REPORT")
614634
SERIAL_PYTEST_ARGS+=(--cov=cachier --cov-report="$COVERAGE_REPORT" --cov-append)
615635

616-
# Print and run the command
617-
print_message $BLUE "Running: $(printf '%q ' "${PYTEST_ARGS[@]}")"
618-
"${PYTEST_ARGS[@]}"
636+
MAIN_TEST_EXIT_CODE=0
637+
SERIAL_TEST_EXIT_CODE=0
638+
639+
if run_pytest_phase "main pytest phase" "${PYTEST_ARGS[@]}"; then
640+
MAIN_TEST_EXIT_CODE=0
641+
else
642+
MAIN_TEST_EXIT_CODE=$?
643+
fi
619644

620645
if [ "$run_serial_local_tests" = true ]; then
621-
print_message $BLUE "Running serial local tests (pickle, memory) with: $(printf '%q ' "${SERIAL_PYTEST_ARGS[@]}")"
622-
"${SERIAL_PYTEST_ARGS[@]}"
646+
if run_pytest_phase "serial local pytest phase" "${SERIAL_PYTEST_ARGS[@]}"; then
647+
SERIAL_TEST_EXIT_CODE=0
648+
else
649+
SERIAL_TEST_EXIT_CODE=$?
650+
fi
623651
else
624652
print_message $BLUE "Skipping serial local tests (pickle, memory) since not requested"
625653
fi
626654

627-
TEST_EXIT_CODE=$?
655+
TEST_EXIT_CODE=0
656+
if [ "$MAIN_TEST_EXIT_CODE" -ne 0 ]; then
657+
TEST_EXIT_CODE=$MAIN_TEST_EXIT_CODE
658+
elif [ "$SERIAL_TEST_EXIT_CODE" -ne 0 ]; then
659+
TEST_EXIT_CODE=$SERIAL_TEST_EXIT_CODE
660+
fi
628661

629662
if [ $TEST_EXIT_CODE -eq 0 ]; then
630663
print_message $GREEN "All tests passed!"
631664
else
632-
print_message $RED "Some tests failed. Exit code: $TEST_EXIT_CODE"
665+
print_message $RED "Some tests failed. Main phase: $MAIN_TEST_EXIT_CODE, serial local phase: $SERIAL_TEST_EXIT_CODE"
633666
fi
634667

635668
# Exit with test status

0 commit comments

Comments
 (0)