Skip to content

Commit 5c7fb40

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

4 files changed

Lines changed: 57 additions & 12 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ jobs:
9090
#CACHIER_TEST_DB: "dummy_db"
9191
#CACHIER_TEST_USERNAME: "myuser"
9292
#CACHIER_TEST_PASSWORD: "yourpassword"
93-
CACHIER_TEST_VS_DOCKERIZED_MONGO: "true"
9493
CACHIER_TEST_REDIS_HOST: "localhost"
9594
CACHIER_TEST_REDIS_PORT: "6379"
9695
CACHIER_TEST_REDIS_DB: "0"
@@ -137,7 +136,7 @@ jobs:
137136
# prefix-key: "mongo-db"
138137
# images: mongo:8
139138
- name: Start MongoDB in docker
140-
if: matrix.backend == 'mongodb'
139+
if: matrix.backend == 'mongodb' && runner.os != 'Windows'
141140
run: |
142141
# start MongoDB in a container
143142
docker run -d -p ${{ env.CACHIER_TEST_PORT }}:27017 --name mongodb mongo:8
@@ -148,6 +147,8 @@ jobs:
148147
149148
- name: Unit tests (DB)
150149
if: matrix.backend == 'mongodb'
150+
env:
151+
CACHIER_TEST_VS_DOCKERIZED_MONGO: ${{ runner.os == 'Windows' && 'false' || 'true' }}
151152
run: pytest -m "mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml
152153
- name: Speed eval
153154
run: python tests/speed_eval.py

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -853,11 +853,11 @@ This script automatically handles Docker container lifecycle, environment variab
853853
# Clean up
854854
docker stop cachier-test-mongo && docker rm cachier-test-mongo
855855
856-
**CI Environment:** The ``CACHIER_TEST_VS_DOCKERIZED_MONGO`` environment variable is set to ``True`` in the GitHub Actions CI environment, which runs tests against a real MongoDB instance on every commit and pull request.
856+
**CI Environment:** GitHub Actions runs MongoDB tests against a real Dockerized MongoDB instance on Linux. Windows MongoDB jobs use the in-memory MongoDB backend because GitHub-hosted Windows runners do not provide a stable Docker daemon for Linux MongoDB containers.
857857

858-
Contributors are encouraged to test against a real MongoDB instance before submitting PRs to ensure compatibility, though the in-memory MongoDB instance serves as a good proxy for most development.
858+
Contributors are encouraged to test against a real MongoDB instance before submitting PRs to ensure compatibility, though the in-memory MongoDB instance serves as a good proxy for most development and CI platform coverage.
859859

860-
**HOWEVER, the tests run against a live MongoDB instance when you submit a PR are the determining tests for deciding whether your code functions correctly against MongoDB.**
860+
**HOWEVER, the Linux tests run against a live MongoDB instance when you submit a PR are the determining tests for deciding whether your code functions correctly against MongoDB.**
861861

862862

863863
Testing all backends locally

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

tests/mongo_tests/helpers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import platform
44
import sys
5+
import tarfile
56
from contextlib import suppress
67
from urllib.parse import quote_plus
78

@@ -41,6 +42,11 @@ class CfgKey:
4142
_COLLECTION_NAME = f"cachier_test_{platform.system()}_{'.'.join(map(str, sys.version_info[:3]))}"
4243

4344

45+
def _configure_safe_tar_extraction_filter() -> None:
46+
if getattr(tarfile.TarFile, "extraction_filter", None) is None and hasattr(tarfile, "data_filter"):
47+
tarfile.TarFile.extraction_filter = staticmethod(tarfile.data_filter)
48+
49+
4450
def _get_cachier_db_mongo_client():
4551
host = quote_plus(CFG[CfgKey.HOST])
4652
port = quote_plus(CFG[CfgKey.PORT])
@@ -55,6 +61,7 @@ def _test_mongetter():
5561
_test_mongetter.client = _get_cachier_db_mongo_client()
5662
else:
5763
print("Using in-memory MongoDB instance for testing.")
64+
_configure_safe_tar_extraction_filter()
5865
_test_mongetter.client = InMemoryMongoClient()
5966
db_obj = _test_mongetter.client["cachier_test"]
6067
if _COLLECTION_NAME not in db_obj.list_collection_names():

0 commit comments

Comments
 (0)