diff --git a/scripts/test-triton.sh b/scripts/test-triton.sh index 2c172eafec..10e63328f6 100755 --- a/scripts/test-triton.sh +++ b/scripts/test-triton.sh @@ -45,6 +45,8 @@ OPTION: --skip-list SKIPLIST --extra-skip-list-suffixes SEMICOLON-SEPARATED LIST OF SUFFIXES --select-from-file SELECTFILE + --test-expr EXPRESSION + --debug-fail " err() { @@ -86,6 +88,8 @@ TRITON_TEST_IGNORE_ERRORS=false SKIP_PIP=false SKIP_PYTORCH=false TEST_UNSKIP=false +TEST_FILTER_EXPRESSION="" +TEST_DEBUG_FAIL=false while (( $# != 0 )); do case "$1" in @@ -273,6 +277,14 @@ while (( $# != 0 )); do TRITON_TEST_SELECTFILE="$(realpath "$2")" shift 2 ;; + --test-expr) + TEST_FILTER_EXPRESSION="$2" + shift 2 + ;; + --debug-fail) + TEST_DEBUG_FAIL=true + shift + ;; --help) echo "$HELP" exit 0 @@ -342,12 +354,44 @@ run_unit_tests() { } run_pytest_command() { - if [[ -n "$TRITON_TEST_SELECTFILE" ]]; then - if pytest "$@" --collect-only > /dev/null 2>&1; then - pytest "$@" + local pytest_args=() + local pytest_expr="" + + # Parse args to separate -k expression + local args=("$@") + for ((i=0; i<${#args[@]}; i++)); do + if [[ "${args[i]}" == "-k" ]]; then + pytest_expr="${args[i+1]}" + i=$((i + 1)) + continue + fi + pytest_args+=("${args[i]}") + done + + # Combine with TEST_FILTER_EXPRESSION + if [[ -n "$TEST_FILTER_EXPRESSION" ]]; then + if [[ -n "$pytest_expr" ]]; then + pytest_expr="($pytest_expr) and ($TEST_FILTER_EXPRESSION)" + else + pytest_expr="$TEST_FILTER_EXPRESSION" + fi + fi + + # Apply -k expression if any + if [[ -n "$pytest_expr" ]]; then + pytest_args+=("-k" "$pytest_expr") + fi + + if [[ "$TEST_DEBUG_FAIL" == true ]]; then + pytest_args+=("--pdb") + fi + + if [[ -n "$TRITON_TEST_SELECTFILE" ]] || [[ -n "$pytest_expr" ]]; then + if pytest "${pytest_args[@]}" --collect-only > /dev/null 2>&1; then + pytest "${pytest_args[@]}" fi else - pytest "$@" + pytest "${pytest_args[@]}" fi }