Skip to content

Commit 493f4e6

Browse files
committed
pySCG: fix pytest filter generation in CI workflow
Fix bash script that generates pytest -k filter to properly handle single directory case. Trim trailing spaces before joining with ' or ' to avoid invalid pytest expressions like 'CWE-703 or '. Signed-off-by: tommcd <[email protected]>
1 parent f9f91ab commit 493f4e6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

.github/workflows/python-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ jobs:
9191
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
9292
run: |
9393
# Extract unique CWE directories from changed files
94-
CHANGED_DIRS=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E 'CWE-|Intro_' | sed 's|docs/Secure-Coding-Guide-for-Python/||' | sed 's|/.*||' | sort -u | tr '\n' ' ')
94+
CHANGED_DIRS=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E 'CWE-|Intro_' | sed 's|docs/Secure-Coding-Guide-for-Python/||' | sed 's|/.*||' | sort -u)
9595
9696
if [ -n "$CHANGED_DIRS" ]; then
9797
echo "::notice::Testing changed directories: $CHANGED_DIRS"
98-
# Build pytest -k filter for changed directories
99-
FILTER=$(echo "$CHANGED_DIRS" | sed 's/ / or /g')
98+
# Build pytest -k filter for changed directories (trim spaces and join with ' or ')
99+
FILTER=$(echo "$CHANGED_DIRS" | tr '\n' ' ' | sed 's/^ *//;s/ *$//' | sed 's/ / or /g')
100100
uv run pytest tests/ --tb=line -q -k "$FILTER" || {
101101
echo "::error::Tests failed. See details above."
102102
exit 1

0 commit comments

Comments
 (0)