Skip to content

Commit 2ae600a

Browse files
committed
Add test expression option to filter tests by their names
Creates an interface for pytest test selection mechanism. Signed-off-by: Sławomir Błauciak <slawomir.blauciak@intel.com>
1 parent 462a07e commit 2ae600a

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

scripts/test-triton.sh

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

5051
err() {
@@ -86,6 +87,7 @@ TRITON_TEST_IGNORE_ERRORS=false
8687
SKIP_PIP=false
8788
SKIP_PYTORCH=false
8889
TEST_UNSKIP=false
90+
TEST_FILTER_EXPRESSION=""
8991

9092
while (( $# != 0 )); do
9193
case "$1" in
@@ -273,6 +275,10 @@ while (( $# != 0 )); do
273275
TRITON_TEST_SELECTFILE="$(realpath "$2")"
274276
shift 2
275277
;;
278+
--test-expr)
279+
TEST_FILTER_EXPRESSION="$2"
280+
shift 2
281+
;;
276282
--help)
277283
echo "$HELP"
278284
exit 0
@@ -342,12 +348,40 @@ run_unit_tests() {
342348
}
343349

344350
run_pytest_command() {
345-
if [[ -n "$TRITON_TEST_SELECTFILE" ]]; then
346-
if pytest "$@" --collect-only > /dev/null 2>&1; then
347-
pytest "$@"
351+
local pytest_args=()
352+
local pytest_expr=""
353+
354+
# Parse args to separate -k expression
355+
local args=("$@")
356+
for ((i=0; i<${#args[@]}; i++)); do
357+
if [[ "${args[i]}" == "-k" ]]; then
358+
pytest_expr="${args[i+1]}"
359+
i=$((i + 1))
360+
continue
361+
fi
362+
pytest_args+=("${args[i]}")
363+
done
364+
365+
# Combine with TEST_FILTER_EXPRESSION
366+
if [[ -n "$TEST_FILTER_EXPRESSION" ]]; then
367+
if [[ -n "$pytest_expr" ]]; then
368+
pytest_expr="($pytest_expr) and ($TEST_FILTER_EXPRESSION)"
369+
else
370+
pytest_expr="$TEST_FILTER_EXPRESSION"
371+
fi
372+
fi
373+
374+
# Apply -k expression if any
375+
if [[ -n "$pytest_expr" ]]; then
376+
pytest_args+=("-k" "$pytest_expr")
377+
fi
378+
379+
if [[ -n "$TRITON_TEST_SELECTFILE" ]] || [[ -n "$pytest_expr" ]]; then
380+
if pytest "${pytest_args[@]}" --collect-only > /dev/null 2>&1; then
381+
pytest "${pytest_args[@]}"
348382
fi
349383
else
350-
pytest "$@"
384+
pytest "${pytest_args[@]}"
351385
fi
352386
}
353387

0 commit comments

Comments
 (0)