You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by vt...@apache.org on 2025/07/31 13:48:37 UTC
(beam) branch fix-python-tasks updated: Revert run_pytest.sh changes
This is an automated email from the ASF dual-hosted git repository.
vterentev pushed a commit to branch fix-python-tasks
in repository https://gitbox.apache.org/repos/asf/beam.git
The following commit(s) were added to refs/heads/fix-python-tasks by this push:
new cfa4d7a4305 Revert run_pytest.sh changes
cfa4d7a4305 is described below
commit cfa4d7a43053ac04f2201180d99272563cfdd8d4
Author: Vitaly Terentyev <vi...@akvelon.com>
AuthorDate: Thu Jul 31 17:48:27 2025 +0400
Revert run_pytest.sh changes
---
.github/workflows/beam_PostCommit_Python.yml | 4 +-
.github/workflows/beam_PreCommit_Python_ML.yml | 4 +-
sdks/python/scripts/run_pytest.sh | 97 +++++---------------------
3 files changed, 21 insertions(+), 84 deletions(-)
diff --git a/.github/workflows/beam_PostCommit_Python.yml b/.github/workflows/beam_PostCommit_Python.yml
index fef02dc8f92..4fc76c50b00 100644
--- a/.github/workflows/beam_PostCommit_Python.yml
+++ b/.github/workflows/beam_PostCommit_Python.yml
@@ -108,8 +108,8 @@ jobs:
-PuseWheelDistribution \
-Pposargs="${{
contains(matrix.os, 'self-hosted') &&
- '-m (not require_docker_in_docker)' ||
- '-m require_docker_in_docker'
+ '-m ''not require_docker_in_docker''' ||
+ '-m ''require_docker_in_docker'''
}}" \
-PpythonVersion=${{ matrix.python_version }} \
env:
diff --git a/.github/workflows/beam_PreCommit_Python_ML.yml b/.github/workflows/beam_PreCommit_Python_ML.yml
index de920428a24..691c21af3ec 100644
--- a/.github/workflows/beam_PreCommit_Python_ML.yml
+++ b/.github/workflows/beam_PreCommit_Python_ML.yml
@@ -105,8 +105,8 @@ jobs:
arguments: |
-Pposargs="${{
contains(matrix.os, 'self-hosted') &&
- 'apache_beam/ml/ -m (not require_docker_in_docker)' ||
- 'apache_beam/ml/ -m require_docker_in_docker'
+ 'apache_beam/ml/ -m ''not require_docker_in_docker''' ||
+ 'apache_beam/ml/ -m ''require_docker_in_docker'''
}}" \
-PpythonVersion=${{ matrix.python_version }}
- name: Archive Python Test Results
diff --git a/sdks/python/scripts/run_pytest.sh b/sdks/python/scripts/run_pytest.sh
index 20fad40b9a2..11bdd4f8577 100755
--- a/sdks/python/scripts/run_pytest.sh
+++ b/sdks/python/scripts/run_pytest.sh
@@ -30,44 +30,26 @@ envname=${1?First argument required: suite base name}
posargs=$2
pytest_args=$3
-# strip leading/trailing quotes from posargs because it can get double quoted as
-# its passed through.
-if [[ $posargs == '"'*'"' ]]; then
- # If wrapped in double quotes, remove them
- posargs="${posargs:1:${#posargs}-2}"
-elif [[ $posargs == "'"*"'" ]]; then
- # If wrapped in single quotes, remove them.
- posargs="${posargs:1:${#posargs}-2}"
-fi
+# strip leading/trailing quotes from posargs because it can get double quoted as its passed through.
+posargs=$(sed -e 's/^"//' -e 's/"$//' -e "s/'$//" -e "s/^'//" <<<$posargs)
echo "pytest_args: $pytest_args"
echo "posargs: $posargs"
# Define the regex for extracting the -m argument value
-marker_regex="-m\s+('[^']+'|\"[^\"]+\"|\([^)]+\)|[^ ]+)"
+marker_regex="-m\s+('[^']+'|\"[^\"]+\"|[^ ]+)"
# Initialize the user_marker variable.
user_marker=""
-# Define regex pattern for quoted strings
-quotes_regex="^[\"\'](.*)[\"\']$"
-
-# Extract the user markers.
-if [[ $posargs =~ $marker_regex ]]; then
- # Get the full match including -m and the marker.
- full_match="${BASH_REMATCH[0]}"
-
- # Get the marker with quotes (this is the first capture group).
- quoted_marker="${BASH_REMATCH[1]}"
-
- # Remove any quotes around the marker.
- if [[ $quoted_marker =~ $quotes_regex ]]; then
- user_marker="${BASH_REMATCH[1]}"
- else
- user_marker="$quoted_marker"
- fi
+# Isolate the user-provided -m argument (matching only).
+if [[ $pytest_args =~ "-m" ]]; then
+ # Extract the marker value using the defined regex.
+ user_marker=$(echo "$pytest_args" | sed -nE "s/.*$marker_regex.*/\1/p")
+fi
- # Remove the entire -m marker portion from posargs.
- posargs="${posargs/$full_match/}"
+# Remove the -m argument from pytest_args (substitution only).
+if [[ -n $user_marker ]]; then
+ pytest_args=$(echo "$pytest_args" | sed -E "s/$marker_regex//")
fi
# Combine user-provided marker with script's internal logic.
@@ -76,65 +58,20 @@ marker_for_sequential_tests="no_xdist"
if [[ -n $user_marker ]]; then
# Combine user marker with internal markers.
- marker_for_parallel_tests="$user_marker and ($marker_for_parallel_tests)"
- marker_for_sequential_tests="$user_marker and ($marker_for_sequential_tests)"
-fi
-
-# Parse posargs to separate pytest options from test paths.
-options=""
-test_paths=""
-
-# Safely split the posargs string into individual arguments.
-eval "set -- $posargs"
-
-# Iterate through arguments.
-while [[ $# -gt 0 ]]; do
- arg="$1"
- shift
-
- # If argument starts with dash, it's an option.
- if [[ "$arg" == -* ]]; then
- options+=" $arg"
-
- # Check if there's a next argument and it doesn't start with a dash.
- # This assumes it's a value for the current option.
- if [[ $# -gt 0 && "$1" != -* ]]; then
- # Get the next argument.
- next_arg="$1"
-
- # Check if it's quoted and remove quotes if needed.
- if [[ $next_arg =~ $quotes_regex ]]; then
- # Extract the content inside quotes.
- next_arg="${BASH_REMATCH[1]}"
- fi
-
- # Add the unquoted value to options.
- options+=" $next_arg"
- shift
- fi
- else
- # Otherwise it's a test path.
- test_paths+=" $arg"
- fi
-done
-
-# Construct the final pytest command arguments.
-pyargs_section=""
-if [[ -n "$test_paths" ]]; then
- pyargs_section="--pyargs $test_paths"
+ marker_for_parallel_tests="($user_marker) and ($marker_for_parallel_tests)"
+ marker_for_sequential_tests="($user_marker) and ($marker_for_sequential_tests)"
fi
-pytest_command_args="$options $pyargs_section"
# Run tests in parallel.
-echo "Running parallel tests with: pytest -m \"$marker_for_parallel_tests\" $pytest_command_args"
+echo "Running parallel tests with: pytest -m \"$marker_for_parallel_tests\" $pytest_args"
pytest -v -rs -o junit_suite_name=${envname} \
- --junitxml=pytest_${envname}.xml -m "$marker_for_parallel_tests" -n 6 --import-mode=importlib ${pytest_args} ${pytest_command_args}
+ --junitxml=pytest_${envname}.xml -m "$marker_for_parallel_tests" -n 6 --import-mode=importlib ${pytest_args} --pyargs ${posargs}
status1=$?
# Run tests sequentially.
-echo "Running sequential tests with: pytest -m \"$marker_for_sequential_tests\" $pytest_command_args"
+echo "Running sequential tests with: pytest -m \"$marker_for_sequential_tests\" $pytest_args"
pytest -v -rs -o junit_suite_name=${envname}_no_xdist \
- --junitxml=pytest_${envname}_no_xdist.xml -m "$marker_for_sequential_tests" --import-mode=importlib ${pytest_args} ${pytest_command_args}
+ --junitxml=pytest_${envname}_no_xdist.xml -m "$marker_for_sequential_tests" --import-mode=importlib ${pytest_args} --pyargs ${posargs}
status2=$?
# Exit with error if no tests were run in either suite (status code 5).