Repository: scikit-learn/scikit-learn
File: build_tools/azure/test_script.sh (Shell)

Code before:
set -eu

# Defines the show_installed_libraries and activate_environment functions.
source build_tools/shared.sh

activate_environment

if [[ "$BUILD_REASON" == "Schedule" ]]; then
    # Enable global random seed randomization to discover seed-sensitive tests
    # only on nightly builds.
    # https://scikit-learn.org/stable/computing/parallelism.html#environment-variables
    export SKLEARN_TESTS_GLOBAL_RANDOM_SEED=$(($RANDOM % 100))
    echo "To reproduce this test run, set the following environment variable:"
    echo "    SKLEARN_TESTS_GLOBAL_RANDOM_SEED=$SKLEARN_TESTS_GLOBAL_RANDOM_SEED",
    echo "See: https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed"

    # Enable global dtype fixture for all nightly builds to discover
    # numerical-sensitive tests.
    # https://scikit-learn.org/stable/computing/parallelism.html#environment-variables
    export SKLEARN_RUN_FLOAT32_TESTS=1
fi

if [[ -z "${COMMIT_MESSAGE+x}" ]]; then
    COMMIT_MESSAGE=$(python build_tools/azure/get_commit_message.py --only-show-message)
fi

if [[ "$COMMIT_MESSAGE" =~ \[float32\] ]]; then
    echo "float32 tests will be run due to commit message"
    export SKLEARN_RUN_FLOAT32_TESTS=1
fi

CHECKOUT_FOLDER=$PWD
mkdir -p $TEST_DIR
cp pyproject.toml $TEST_DIR
cd $TEST_DIR

python -c "import joblib; print(f'Number of cores (physical): \
{joblib.cpu_count()} ({joblib.cpu_count(only_physical_cores=True)})')"
python -c "import sklearn; sklearn.show_versions()"

show_installed_libraries
show_cpu_info

NUM_CORES=$(python -c "import joblib; print(joblib.cpu_count())")
TEST_CMD="python -m pytest --showlocals --durations=20 --junitxml=$JUNITXML -o junit_family=legacy"

if [[ "$COVERAGE" == "true" ]]; then
    # Note: --cov-report= is used to disable too long text output report in the
    # CI logs. The coverage data is consolidated by codecov to get an online
    # web report across all the platforms so there is no need for this text
    # report that otherwise hides the test failures and forces long scrolls in

Review comment (suggestion):
Here, I have chosen to distinguish between an empty variable and an unset variable.
If the variable is set, regardless of whether the message is empty or not, we shouldn't call `build_tools/azure/get_commit_message.py`.

Code after:
set -e

# Defines the show_installed_libraries and activate_environment functions.
source build_tools/shared.sh

activate_environment

if [[ "$BUILD_REASON" == "Schedule" ]]; then
    # Enable global random seed randomization to discover seed-sensitive tests
    # only on nightly builds.
    # https://scikit-learn.org/stable/computing/parallelism.html#environment-variables
    export SKLEARN_TESTS_GLOBAL_RANDOM_SEED=$(($RANDOM % 100))
    echo "To reproduce this test run, set the following environment variable:"
    echo "    SKLEARN_TESTS_GLOBAL_RANDOM_SEED=$SKLEARN_TESTS_GLOBAL_RANDOM_SEED",
    echo "See: https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed"

    # Enable global dtype fixture for all nightly builds to discover
    # numerical-sensitive tests.
    # https://scikit-learn.org/stable/computing/parallelism.html#environment-variables
    export SKLEARN_RUN_FLOAT32_TESTS=1
fi

# In GitHub Action (especially in `.github/workflows/unit-tests.yml` which
# calls this script), the environment variable `COMMIT_MESSAGE` is already set
# to the latest commit message.
if [[ -z "${COMMIT_MESSAGE+x}" ]]; then
    # If 'COMMIT_MESSAGE' is unset we are in Azure, and we retrieve the commit
    # message via the get_commit_message.py script which uses Azure-specific
    # variables, for example 'BUILD_SOURCEVERSIONMESSAGE'.
    COMMIT_MESSAGE=$(python build_tools/azure/get_commit_message.py --only-show-message)
fi

if [[ "$COMMIT_MESSAGE" =~ \[float32\] ]]; then
    echo "float32 tests will be run due to commit message"
    export SKLEARN_RUN_FLOAT32_TESTS=1
fi

CHECKOUT_FOLDER=$PWD
mkdir -p $TEST_DIR
cp pyproject.toml $TEST_DIR
cd $TEST_DIR

python -c "import joblib; print(f'Number of cores (physical): \
{joblib.cpu_count()} ({joblib.cpu_count(only_physical_cores=True)})')"
python -c "import sklearn; sklearn.show_versions()"

show_installed_libraries
show_cpu_info

NUM_CORES=$(python -c "import joblib; print(joblib.cpu_count())")
TEST_CMD="python -m pytest --showlocals --durations=20 --junitxml=$JUNITXML -o junit_family=legacy"