Skip to content

Commit a7a9127

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

1 file changed

Lines changed: 44 additions & 7 deletions

File tree

scripts/test-local.sh

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ 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+
"$@"
322+
local phase_exit_code=$?
323+
324+
if [ "$phase_exit_code" -eq 0 ]; then
325+
print_message $GREEN "$phase_name passed"
326+
else
327+
print_message $RED "$phase_name failed with exit code $phase_exit_code"
328+
fi
329+
330+
return "$phase_exit_code"
331+
}
332+
315333
# MongoDB functions
316334
start_mongodb() {
317335
print_message $YELLOW "Starting MongoDB container..."
@@ -613,23 +631,42 @@ EOF
613631
PYTEST_ARGS+=(--cov=cachier --cov-report="$COVERAGE_REPORT")
614632
SERIAL_PYTEST_ARGS+=(--cov=cachier --cov-report="$COVERAGE_REPORT" --cov-append)
615633

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

620647
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[@]}"
648+
if run_pytest_phase "serial local pytest phase" "${SERIAL_PYTEST_ARGS[@]}"; then
649+
SERIAL_TEST_EXIT_CODE=0
650+
SERIAL_TEST_STATUS="passed"
651+
else
652+
SERIAL_TEST_EXIT_CODE=$?
653+
SERIAL_TEST_STATUS="failed ($SERIAL_TEST_EXIT_CODE)"
654+
fi
623655
else
624656
print_message $BLUE "Skipping serial local tests (pickle, memory) since not requested"
625657
fi
626658

627-
TEST_EXIT_CODE=$?
659+
TEST_EXIT_CODE=0
660+
if [ "$MAIN_TEST_EXIT_CODE" -ne 0 ]; then
661+
TEST_EXIT_CODE=$MAIN_TEST_EXIT_CODE
662+
elif [ "$SERIAL_TEST_EXIT_CODE" -ne 0 ]; then
663+
TEST_EXIT_CODE=$SERIAL_TEST_EXIT_CODE
664+
fi
628665

629666
if [ $TEST_EXIT_CODE -eq 0 ]; then
630667
print_message $GREEN "All tests passed!"
631668
else
632-
print_message $RED "Some tests failed. Exit code: $TEST_EXIT_CODE"
669+
print_message $RED "Some tests failed. Main phase: $MAIN_TEST_STATUS, serial local phase: $SERIAL_TEST_STATUS"
633670
fi
634671

635672
# Exit with test status

0 commit comments

Comments
 (0)