8000 CI allow to run only selected tests but on all random seeds by jeremiedbb · Pull Request #23026 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

CI allow to run only selected tests but on all random seeds #23026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a5cafe2
Allow to run only a subset of tests but on all random seeds
jeremiedbb Apr 1, 2022
91a0df4
[all random seeds]
jeremiedbb Apr 1, 2022
041edc1
parse commit message in templates
jeremiedbb Apr 5, 2022
25d7b2f
tst [all random seeds]
jeremiedbb Apr 5, 2022
d87ef25
new tst [all random seeds]
jeremiedbb Apr 5, 2022
39f74fd
new tst [all random seeds]
jeremiedbb Apr 5, 2022
c018fe6
new tst [all random seeds]
jeremiedbb Apr 5, 2022
6383fd1
debug win [all random seeds]
jeremiedbb Apr 5, 2022
59199a4
tst [all random seeds]
jeremiedbb Apr 5, 2022
d8c3c6e
debug win [all random seeds]
jeremiedbb Apr 5, 2022
147d540
tst [all random seeds]
jeremiedbb Apr 5, 2022
59ac79f
python script [all random seeds]
jeremiedbb Apr 11, 2022
772adfe
python script [all random seeds]
jeremiedbb Apr 11, 2022
28e545b
python script [all random seeds]
jeremiedbb Apr 11, 2022
156df8d
python script [all random seeds]
jeremiedbb Apr 11, 2022
0fa3718
cln [all random seeds]
jeremiedbb Apr 11, 2022
0cbaeef
exp [all random seeds]
jeremiedbb Apr 11, 2022
e63c0be
cln [all random seeds]
jeremiedbb Apr 11, 2022
9adbae0
condition on pull requests [all random seeds]
jeremiedbb Apr 11, 2022
9262c35
exp [all random seeds]
jeremiedbb Apr 12, 2022
7f11575
exp [all random seeds]
jeremiedbb Apr 12, 2022
e0ec52d
exp [all random seeds]
jeremiedbb Apr 12, 2022
39d4ce1
exp [all random seeds]
jeremiedbb Apr 12, 2022
d9dfa52
exp [all random seeds]
jeremiedbb Apr 12, 2022
b6d830f
exp [all random seeds]
jeremiedbb Apr 12, 2022
37ce49d
cln [all random seeds]
jeremiedbb Apr 12, 2022
30aa92f
cln [all random seeds]
jeremiedbb Apr 12, 2022
576d3ab
lint [all random seeds]
jeremiedbb Apr 12, 2022
b180ecd
cln [all random seeds]
jeremiedbb Apr 12, 2022
9e4c030
cln [all random seeds]
jeremiedbb Apr 12, 2022
7ca5567
cln [all random seeds]
jeremiedbb Apr 12, 2022
0bf0b30
cln [all random seeds]
jeremiedbb Apr 12, 2022
2f51d13
cln [all random seeds]
jeremiedbb Apr 12, 2022
2df7786
exp [all random seeds]
jeremiedbb Apr 12, 2022
5a1f29f
exp [all random seeds]
jeremiedbb Apr 12, 2022
be9420b
Merge branch 'master' into tst-random-seed-all
jeremiedbb Apr 13, 2022
9e36617
adress comments [all random seeds]
jeremiedbb Apr 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ jobs:
pool:
vmImage: ubuntu-20.04
steps:
- bash: |
set -ex
if [[ $BUILD_REASON == "PullRequest" ]]; then
# By default pull requests use refs/pull/PULL_ID/merge as the source branch
# which has a "Merge ID into ID" as a commit message. The latest commit
# message is the second to last commit
COMMIT_ID=$(echo $BUILD_SOURCEVERSIONMESSAGE | awk '{print $2}')
message=$(git log $COMMIT_ID -1 --pretty=%B)
else
message=$BUILD_SOURCEVERSIONMESSAGE
fi
echo "##vso[task.setvariable variable=message;isOutput=true]$message"
- bash: python build_tools/azure/get_commit_message.py
name: commit
displayName: Get source version message

Expand Down
29 changes: 29 additions & 0 deletions build_tools/azure/get_commit_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import subprocess


def get_commit_message():
"""Retrieve the commit message."""
build_source_version_message = os.environ["BUILD_SOURCEVERSIONMESSAGE"]

if os.environ["BUILD_REASON"] == "PullRequest":
# By default pull requests use refs/pull/PULL_ID/merge as the source branch
# which has a "Merge ID into ID" as a commit message. The latest commit
# message is the second to last commit
commit_id = build_source_version_message.split()[1]
git_cmd = ["git", "log", commit_id, "-1", "--pretty=%B"]
commit_message = subprocess.run(
git_cmd, capture_output=True, text=True
).stdout.strip()
else:
commit_message = build_source_version_message

return commit_message


if __name__ == "__main__":
# set the environment variable to be propagated to other steps
commit_message = get_commit_message()
print(f"##vso[task.setvariable variable=message;isOutput=true]{commit_message}")

print(f"commit message: {commit_message}") # helps debugging
31 changes: 31 additions & 0 deletions build_tools/azure/get_selected_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from get_commit_message import get_commit_message


def get_selected_tests():
"""Parse the commit message to check if pytest should run only specific tests.

If so, selected tests will be run with SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all".

The commit message must take the form:
<title> [all random seeds]
<test_name_1>
<test_name_2>
...
"""
commit_message = get_commit_message()

if "[all random seeds]" in commit_message:
selected_tests = commit_message.split("[all random seeds]")[1].strip()
selected_tests = selected_tests.replace("\n", " or ")
else:
selected_tests = ""

return selected_tests


if __name__ == "__main__":
# set the environment variable to be propagated to other steps
selected_tests = get_selected_tests()
print(f"##vso[task.setvariable variable=SELECTED_TESTS]'{selected_tests}'")

print(f"selected tests: {selected_tests}") # helps debugging
20 changes: 12 additions & 8 deletions build_tools/azure/posix-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ jobs:
${{ insert }}: ${{ parameters.matrix }}

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
addToPath: false
name: pyTools
displayName: Select python version to run CI python scripts
- bash: $(pyTools.pythonLocation)/bin/python build_tools/azure/get_selected_tests.py
displayName: Check selected tests for all random seeds
condition: eq(variables['Build.Reason'], 'PullRequest')
- task: Cache@2
inputs:
key: '"ccache-v1" | "$(Agent.JobName)" | "$(Build.BuildNumber)"'
Expand Down Expand Up @@ -85,6 +94,7 @@ jobs:
-e OPENBLAS_NUM_THREADS=$OPENBLAS_NUM_THREADS
-e SKLEARN_SKIP_NETWORK_TESTS=$SKLEARN_SKIP_NETWORK_TESTS
-e BLAS=$BLAS
-e SELECTED_TESTS="$SELECTED_TESTS"
-e CPU_COUNT=$CPU_COUNT
-e CCACHE_DIR=/ccache
-e CCACHE_COMPRESS=$CCACHE_COMPRESS
8000 Expand All @@ -107,12 +117,6 @@ jobs:
docker container stop skcontainer
displayName: 'Stop container'
condition: always()
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
displayName: Place Python into path to update issue tracker
condition: and(succeededOrFailed(), eq(variables['CREATE_ISSUE_ON_TRACKER'], 'true'),
eq(variables['Build.Reason'], 'Schedule'))
- bash: |
set -ex
if [[ $(BOT_GITHUB_TOKEN) == "" ]]; then
Expand All @@ -124,8 +128,8 @@ jobs:
CI_NAME="$SYSTEM_JOBIDENTIFIER"
ISSUE_REPO="$BUILD_REPOSITORY_NAME"

pip install defusedxml PyGithub
python maint_tools/update_tracking_issue.py \
$(pyTools.pythonLocation)/bin/pip install defusedxml PyGithub
$(pyTools.pythonLocation)/bin/python maint_tools/update_tracking_issue.py \
$(BOT_GITHUB_TOKEN) \
$CI_NAME \
$ISSUE_REPO \
Expand Down
26 changes: 16 additions & 10 deletions build_tools/azure/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ jobs:
${{ insert }}: ${{ parameters.matrix }}

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
addToPath: false
name: pyTools
displayName: Select python version to run CI python scripts
- bash: $(pyTools.pythonLocation)/bin/python build_tools/azure/get_selected_tests.py
displayName: Check selected tests for all random seeds
condition: eq(variables['Build.Reason'], 'PullRequest')
- bash: echo "##vso[task.prependpath]$CONDA/bin"
displayName: Add conda to PATH
condition: startsWith(variables['DISTRIB'], 'conda')
Expand All @@ -65,22 +74,18 @@ jobs:
- script: |
build_tools/azure/test_docs.sh
displayName: 'Test Docs'
condition: eq(variables['SELECTED_TESTS'], '')
- script: |
build_tools/azure/test_pytest_soft_dependency.sh
displayName: 'Test Soft Dependency'
condition: eq(variables['CHECK_PYTEST_SOFT_DEPENDENCY'], 'true')
condition: and(eq(variables['CHECK_PYTEST_SOFT_DEPENDENCY'], 'true'),
eq(variables['SELECTED_TESTS'], ''))
- task: PublishTestResults@2
inputs:
testResultsFiles: '$(TEST_DIR)/$(JUNITXML)'
testRunTitle: ${{ format('{0}-$(Agent.JobName)', parameters.name) }}
displayName: 'Publish Test Results'
condition: succeededOrFailed()
- task: UsePythonVersion@0
inputs:
versionSpec: '3.9'
displayName: Place Python into path to update issue tracker
condition: and(succeededOrFailed(), eq(variables['CREATE_ISSUE_ON_TRACKER'], 'true'),
eq(variables['Build.Reason'], 'Schedule'))
- bash: |
set -ex
if [[ $(BOT_GITHUB_TOKEN) == "" ]]; then
Expand All @@ -92,8 +97,8 @@ jobs:
CI_NAME="$SYSTEM_JOBIDENTIFIER"
ISSUE_REPO="$BUILD_REPOSITORY_NAME"

pip install defusedxml PyGithub
python maint_tools/update_tracking_issue.py \
$(pyTools.pythonLocation)/bin/pip install defusedxml PyGithub
$(pyTools.pythonLocation)/bin/python maint_tools/update_tracking_issue.py \
$(BOT_GITHUB_TOKEN) \
$CI_NAME \
$ISSUE_REPO \
Expand All @@ -106,7 +111,8 @@ jobs:
eq(variables['Build.Reason'], 'Schedule'))
- script: |
build_tools/azure/upload_codecov.sh
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'))
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
eq(variables['SELECTED_TESTS'], ''))
displayName: 'Upload To Codecov'
env:
CODECOV_TOKEN: $(CODECOV_TOKEN)
7 changes: 7 additions & 0 deletions build_tools/azure/test_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ if [[ "$SHOW_SHORT_SUMMARY" == "true" ]]; then
TEST_CMD="$TEST_CMD -ra"
fi

if [[ "$SELECTED_TESTS" != "" ]]; then
TEST_CMD="$TEST_CMD -k $SELECTED_TESTS"

# Override to make selected tests run on all random seeds
export SKLEARN_TESTS_GLOBAL_RANDOM_SEED="all"
fi

set -x
eval "$TEST_CMD --pyargs sklearn"
set +x
6 changes: 5 additions & 1 deletion build_tools/azure/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
${{ insert }}: ${{ parameters.matrix }}

steps:
- bash: python build_tools/azure/get_selected_tests.py
displayName: Check selected tests for all random seeds
condition: eq(variables['Build.Reason'], 'PullRequest')
- bash: echo "##vso[task.prependpath]$CONDA/Scripts"
displayName: Add conda to PATH for 64 bit Python
condition: eq(variables['PYTHON_ARCH'], '64')
Expand All @@ -41,7 +44,8 @@ jobs:
- bash: ./build_tools/azure/test_script.sh
displayName: 'Test Library'
- bash: ./build_tools/azure/upload_codecov.sh
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'))
condition: and(succeeded(), eq(variables['COVERAGE'], 'true'),
eq(variables['SELECTED_TESTS'], ''))
displayName: 'Upload To Codecov'
env:
CODECOV_TOKEN: $(CODECOV_TOKEN)
Expand Down
0