@@ -25,6 +25,7 @@ COVERAGE_REPORT="term"
2525KEEP_RUNNING=false
2626SELECTED_CORES=" "
2727INCLUDE_LOCAL_CORES=false
28+ TEST_FILES=" "
2829
2930# Function to print colored messages
3031print_message () {
@@ -54,6 +55,7 @@ OPTIONS:
5455 -v, --verbose Show verbose output
5556 -k, --keep-running Keep containers running after tests
5657 -h, --html-coverage Generate HTML coverage report
58+ -f, --files Specify test files to run (can be used multiple times)
5759 --help Show this help message
5860
5961EXAMPLES:
@@ -62,6 +64,7 @@ EXAMPLES:
6264 $0 all # Run all backend tests
6365 $0 external -k # Run external backends, keep containers
6466 $0 mongo memory -v # Run MongoDB and memory tests verbosely
67+ $0 all -f tests/test_main.py -f tests/test_redis_core_coverage.py # Run specific test files
6568
6669ENVIRONMENT:
6770 You can also set cores via CACHIER_TEST_CORES environment variable:
@@ -85,6 +88,16 @@ while [[ $# -gt 0 ]]; do
8588 COVERAGE_REPORT=" html"
8689 shift
8790 ;;
91+ -f|--files)
92+ shift
93+ if [[ $# -eq 0 ]] || [[ " $1 " == -* ]]; then
94+ print_message $RED " Error: -f/--files requires a file argument"
95+ usage
96+ exit 1
97+ fi
98+ TEST_FILES=" $TEST_FILES $1 "
99+ shift
100+ ;;
88101 --help)
89102 usage
90103 exit 0
@@ -473,26 +486,47 @@ main() {
473486 done
474487
475488 # Run pytest
476- # Check if we selected all cores - if so, run all tests without marker filtering
477- all_cores=" memory mongo pickle redis sql"
478- selected_sorted=$( echo " $SELECTED_CORES " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
479- all_sorted=$( echo " $all_cores " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
480-
481- if [ " $selected_sorted " = " $all_sorted " ]; then
482- print_message $BLUE " Running: pytest (all tests, including unmarked)"
483- if [ " $VERBOSE " = true ]; then
484- pytest -v --cov=cachier --cov-report=$COVERAGE_REPORT
485- else
486- pytest --cov=cachier --cov-report=$COVERAGE_REPORT
489+ # Build pytest command
490+ PYTEST_CMD=" pytest"
491+
492+ # Add test files if specified
493+ if [ -n " $TEST_FILES " ]; then
494+ PYTEST_CMD=" $PYTEST_CMD $TEST_FILES "
495+ print_message $BLUE " Test files specified: $TEST_FILES "
496+ fi
497+
498+ # Add markers if needed (only if no specific test files were given)
499+ if [ -z " $TEST_FILES " ]; then
500+ # Check if we selected all cores - if so, run all tests without marker filtering
501+ all_cores=" memory mongo pickle redis sql"
502+ selected_sorted=$( echo " $SELECTED_CORES " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
503+ all_sorted=$( echo " $all_cores " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
504+
505+ if [ " $selected_sorted " != " $all_sorted " ]; then
506+ PYTEST_CMD=" $PYTEST_CMD -m \" $pytest_markers \" "
487507 fi
488508 else
489- print_message $BLUE " Running: pytest -m \" $pytest_markers \" "
490- if [ " $VERBOSE " = true ]; then
491- pytest -v -m " $pytest_markers " --cov=cachier --cov-report=$COVERAGE_REPORT
492- else
493- pytest -m " $pytest_markers " --cov=cachier --cov-report=$COVERAGE_REPORT
509+ # When test files are specified, still apply markers if not running all cores
510+ all_cores=" memory mongo pickle redis sql"
511+ selected_sorted=$( echo " $SELECTED_CORES " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
512+ all_sorted=$( echo " $all_cores " | tr ' ' ' \n' | sort | tr ' \n' ' ' | xargs)
513+
514+ if [ " $selected_sorted " != " $all_sorted " ]; then
515+ PYTEST_CMD=" $PYTEST_CMD -m \" $pytest_markers \" "
494516 fi
495517 fi
518+
519+ # Add verbose flag if needed
520+ if [ " $VERBOSE " = true ]; then
521+ PYTEST_CMD=" $PYTEST_CMD -v"
522+ fi
523+
524+ # Add coverage options
525+ PYTEST_CMD=" $PYTEST_CMD --cov=cachier --cov-report=$COVERAGE_REPORT "
526+
527+ # Print and run the command
528+ print_message $BLUE " Running: $PYTEST_CMD "
529+ eval $PYTEST_CMD
496530
497531 TEST_EXIT_CODE=$?
498532
0 commit comments