enable parallel tests with pytest-xdist and pytest-split #3358
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: tests | |
on: | |
push: | |
branches: | |
- master | |
pull_request: null | |
merge_group: null | |
env: | |
PY_COLORS: "1" | |
IMAGE_NAME: conda-forge-tick | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
tests: | |
name: tests | |
runs-on: "ubuntu-latest" | |
permissions: | |
actions: write # for deleting cache entries | |
contents: read | |
strategy: | |
# continue running the tests even if one of the groups fails | |
fail-fast: false | |
matrix: | |
# if change the number of groups here, also change it next to --splits below | |
group: [1, 2] | |
defaults: | |
run: | |
shell: bash -leo pipefail {0} | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1 | |
with: | |
environment-file: conda-lock.yml | |
environment-name: cf-scripts | |
condarc-file: autotick-bot/condarc | |
- name: configure conda and install code | |
run: | | |
export GIT_FULL_HASH=`git rev-parse HEAD` | |
export RUN_URL="" | |
pip install --no-deps --no-build-isolation -e . | |
- name: test versions | |
run: | | |
cd .. | |
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'" | |
cd - | |
pip uninstall conda-forge-tick --yes | |
rm -rf dist/* | |
python -m build --sdist . --outdir dist | |
pip install --no-deps --no-build-isolation dist/*.tar.gz | |
cd .. | |
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'" | |
cd - | |
pip uninstall conda-forge-tick --yes | |
python -m pip install -v --no-deps --no-build-isolation -e . | |
- name: Start MongoDB | |
uses: MongoCamp/mongodb-github-action@e76ad215d47c31a99b4b0b1fde05f6cd1185df1a # e76ad215d47c31a99b4b0b1fde05f6cd1185df1a | |
with: | |
mongodb-version: "latest" | |
- name: test mongodb is OK | |
run: | | |
python -c "from pymongo import MongoClient; import os; print(MongoClient(os.environ['MONGODB_CONNECTION_STRING']))" | |
env: | |
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000" | |
- name: build docker image | |
run: | | |
docker build -t ${{ env.IMAGE_NAME }}:test . | |
# Save Test Durations logic: | |
# https://github.com/jerry-git/pytest-split/issues/20#issuecomment-1682947832 | |
- name: "[Test Durations] Restore Test Durations (1)" | |
id: test-duration-cache-restore-1 | |
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 | |
with: | |
path: .test_durations.1 | |
key: test-durations-1 | |
- name: "[Test Durations] Restore Test Durations (2)" | |
id: test-duration-cache-restore-2 | |
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 | |
with: | |
path: .test_durations.2 | |
key: test-durations-2 | |
- name: "[Test Durations] Combine Test Duration Cache Files" | |
if: steps.test-duration-cache-restore-1.outputs.cache-hit == 'true' && steps.test-duration-cache-restore-2.outputs.cache-hit == 'true' | |
run: | | |
jq '. + input' .test_durations.1 .test_durations.2 > .test_durations | |
- name: run pytest | |
run: | | |
export TEST_BOT_TOKEN_VAL=unpassword | |
export BOT_TOKEN=${TEST_BOT_TOKEN_VAL} | |
# note: we do not use pytest-xdist (-n auto) here for now because they interfere with hiding the | |
# MONGODB_CONNECTION_STRING sensitive environment variable | |
pytest \ | |
-v \ | |
--splits 2 --group ${{ matrix.group }} \ | |
--store-durations \ | |
--durations-path=.test_durations.${{ matrix.group }} \ | |
--randomly-seed=${{ github.run_id }} \ | |
--splitting-algorithm least_duration \ | |
--cov=conda_forge_tick \ | |
--cov=tests \ | |
--cov-config=.coveragerc \ | |
--cov-report=term-missing \ | |
--cov-report=xml \ | |
--durations=10 \ | |
--ignore=tests/model \ | |
tests | |
env: | |
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000" | |
- name: "[Test Duration] Delete test duration cache (${{ matrix.group }})" | |
continue-on-error: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh extension install actions/gh-actions-cache | |
gh actions-cache delete test-durations-${{ matrix.group }} -R ${{ github.repository }} --confirm | |
- name: "[Test Durations] Save Test Durations" | |
id: test-duration-cache-save | |
uses: actions/cache/save@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4 | |
if: always() | |
with: | |
path: .test_durations.${{ matrix.group }} | |
key: test-durations-${{ matrix.group }} | |
- name: Upload coverage | |
uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4 | |
with: | |
name: coverage-${{ matrix.group }} | |
path: .coverage | |
test-coverage: | |
name: test-coverage | |
needs: tests | |
runs-on: "ubuntu-latest" | |
defaults: | |
run: | |
shell: bash -leo pipefail {0} | |
steps: | |
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 | |
- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1 | |
with: | |
environment-file: conda-lock.yml | |
environment-name: cf-scripts | |
condarc-file: autotick-bot/condarc | |
- name: Download Coverage Artifacts | |
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 | |
with: | |
pattern: coverage-* | |
- name: Combine Coverage | |
run: | | |
coverage combine coverage-*/.coverage* | |
coverage xml | |
- name: upload codecov | |
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} |