Skip to content

Commit ef7d239

Browse files
authored
Add test name filtering and Python debug options to the test script (#5435)
FYI: https://docs.pytest.org/en/stable/example/markers.html#using-k-expr-to-select-tests-based-on-their-name This change adds an interface with the -k param for pytest, for quick test selection and the --pdb option, to enable Python debug for failed tests: --test-expr EXPRESSION - Filters tests by substrings --debug-fail - Enables auto debug --------- Signed-off-by: Sławomir Błauciak <slawomir.blauciak@intel.com>
1 parent e57e5ed commit ef7d239

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

scripts/test-triton.sh

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ OPTION:
4545
--skip-list SKIPLIST
4646
--extra-skip-list-suffixes SEMICOLON-SEPARATED LIST OF SUFFIXES
4747
--select-from-file SELECTFILE
48+
--test-expr EXPRESSION
49+
--debug-fail
4850
"
4951

5052
err() {
@@ -86,6 +88,8 @@ TRITON_TEST_IGNORE_ERRORS=false
8688
SKIP_PIP=false
8789
SKIP_PYTORCH=false
8890
TEST_UNSKIP=false
91+
TEST_FILTER_EXPRESSION=""
92+
TEST_DEBUG_FAIL=false
8993

9094
while (( $# != 0 )); do
9195
case "$1" in
@@ -273,6 +277,14 @@ while (( $# != 0 )); do
273277
TRITON_TEST_SELECTFILE="$(realpath "$2")"
274278
shift 2
275279
;;
280+
--test-expr)
281+
TEST_FILTER_EXPRESSION="$2"
282+
shift 2
283+
;;
284+
--debug-fail)
285+
TEST_DEBUG_FAIL=true
286+
shift
287+
;;
276288
--help)
277289
echo "$HELP"
278290
exit 0
@@ -342,12 +354,44 @@ run_unit_tests() {
342354
}
343355

344356
run_pytest_command() {
345-
if [[ -n "$TRITON_TEST_SELECTFILE" ]]; then
346-
if pytest "$@" --collect-only > /dev/null 2>&1; then
347-
pytest "$@"
357+
local pytest_args=()
358+
local pytest_expr=""
359+
360+
# Parse args to separate -k expression
361+
local args=("$@")
362+
for ((i=0; i<${#args[@]}; i++)); do
363+
if [[ "${args[i]}" == "-k" ]]; then
364+
pytest_expr="${args[i+1]}"
365+
i=$((i + 1))
366+
continue
367+
fi
368+
pytest_args+=("${args[i]}")
369+
done
370+
371+
# Combine with TEST_FILTER_EXPRESSION
372+
if [[ -n "$TEST_FILTER_EXPRESSION" ]]; then
373+
if [[ -n "$pytest_expr" ]]; then
374+
pytest_expr="($pytest_expr) and ($TEST_FILTER_EXPRESSION)"
375+
else
376+
pytest_expr="$TEST_FILTER_EXPRESSION"
377+
fi
378+
fi
379+
380+
# Apply -k expression if any
381+
if [[ -n "$pytest_expr" ]]; then
382+
pytest_args+=("-k" "$pytest_expr")
383+
fi
384+
385+
if [[ "$TEST_DEBUG_FAIL" == true ]]; then
386+
pytest_args+=("--pdb")
387+
fi
388+
389+
if [[ -n "$TRITON_TEST_SELECTFILE" ]] || [[ -n "$pytest_expr" ]]; then
390+
if pytest "${pytest_args[@]}" --collect-only > /dev/null 2>&1; then
391+
pytest "${pytest_args[@]}"
348392
fi
349393
else
350-
pytest "$@"
394+
pytest "${pytest_args[@]}"
351395
fi
352396
}
353397

0 commit comments

Comments
 (0)