[Guides](https://checklane.sh/guides) · Checked on 28 November 2026

# How do I split tests across a GitHub Actions matrix?

Give each [matrix job](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/run-job-variations) a different slice of the same test list. For pytest, one job can take the first, third and fifth files, and the other the second, fourth and sixth, continuing to the end. If both jobs call pytest without selecting files, both run the whole suite.

## Our run of SymPy 1.14.0 (three modules) on 28 November 2026

One cold run per runner. Warm times are the median of three runs, with the range in parentheses.

Time in seconds by workload and runner
| Workload | GitHub-hosted (2 vCPU) | Checklane (2 vCPU) |
| --- | --- | --- |
| Cold wheels · serial job | 649 s | 275 s |
| Cold wheels · two shards | 388 s | 200 s |
| Warm wheels · serial job | 540 s (415–679) | 263 s (263–264) |
| Warm wheels · two shards | 349 s (332–469) | 191 s (189–196) |

On 28 November 2026 we ran the same SymPy revision with Python 3.12.16 on two-vCPU runners in a private repository. Each cell measures seconds from the first job starting to the last job finishing for that configuration, including setup but excluding the initial queue. Each job downloaded wheels on the first attempt and restored its exact wheel cache on three reruns. Every attempt still executed the tests. These ranges describe this suite, not other workloads.

## Compare two shards with one serial run

1.  The workflow below checks out [SymPy 1.14.0](https://github.com/sympy/sympy/tree/16fa855354eb7bcabd3fe10993841e03b1382692) under its [BSD license](https://github.com/sympy/sympy/blob/16fa855354eb7bcabd3fe10993841e03b1382692/LICENSE). It tests the integrals, polynomials and solvers modules with the project’s default pytest selection. Save it under `.github/workflows/` and push the `matrix-sympy-v1` branch to reproduce it.
    
2.  The `all` job is the baseline. The other two jobs take alternating files from the same ordered list. Compare the test IDs and outcomes in the verbose logs: each baseline ID should appear on exactly one shard with the same result. Once you verify the split, remove `all` and choose one runner label for normal CI.
    

### Tested on 28 November 2026

Show the workflow YAML

```yaml
name: Shard SymPy tests
on:
  push:
    branches: [matrix-sympy-v1]
permissions:
  contents: read
jobs:
  test:
    name: ${{ matrix.runner }} / ${{ matrix.part }}
    runs-on: ${{ matrix.runner }}
    timeout-minutes: 30
    strategy:
      fail-fast: false
      matrix:
        runner: [ubuntu-latest, checklane-2vcpu]
        part: [all, odd, even]
    steps:
      - name: Verify two CPUs
        run: nproc && test "$(nproc)" = 2
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          repository: sympy/sympy
          ref: 16fa855354eb7bcabd3fe10993841e03b1382692 # SymPy 1.14.0
          persist-credentials: false
      - uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
        with:
          python-version: '3.12.16'
      - name: Restore wheels
        id: wheels
        uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
        with:
          path: wheels
          key: sympy-matrix-v1-${{ github.sha }}-${{ matrix.runner }}-${{ matrix.part }}
      - name: Download wheels on a miss
        if: steps.wheels.outputs.cache-hit != 'true'
        run: |
          python -m pip download --no-cache-dir --only-binary=:all: -d wheels pytest==8.3.5 mpmath==1.3.0 hypothesis==6.131.9 sortedcontainers==2.4.0 attrs==25.3.0 iniconfig==2.1.0 packaging==25.0 pluggy==1.5.0
      - name: Install from wheels
        run: python -m pip install --no-index --find-links=wheels pytest==8.3.5 mpmath==1.3.0 hypothesis==6.131.9
      - name: Test
        shell: bash
        env:
          PART: ${{ matrix.part }}
          LC_ALL: C
          PYTHONHASHSEED: '0'
        run: |
          files=(sympy/{integrals,polys,solvers}/tests/test_*.py)
          selected=()
          for i in "${!files[@]}"; do
            if [[ $PART == all || $PART == odd && $((i%2)) == 0 || $PART == even && $((i%2)) == 1 ]]; then
              selected+=("${files[i]}")
            fi
          done
          python -m pytest -v --color=no --hypothesis-seed=1 "${selected[@]}"
```

Run on 28 November 2026 on checklane-2vcpu: the serial job and the combined shards both reported 1,714 passes, 56 expected failures and two skips. The same test IDs and outcomes matched on ubuntu-latest. The project’s default selection excluded 63 other tests.

Related guide: [How do I speed up GitHub Actions?](https://checklane.sh/guides/speed-up-github-actions)

## Frequently asked questions

### Will a Python version matrix split my tests?

A version matrix repeats the test command in each environment. To test every file on each version, keep the version axis and add a shard axis. Pass only that shard’s files to pytest.

[GitHub: how matrix combinations work](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/run-job-variations)

### Why did one shard finish much later than the other?

Alternating files balances file counts, not test durations. Run pytest with --durations=10 on the slower shard to find the expensive tests. Rebalance those files before adding a third job.

[pytest: profiling test durations](https://docs.pytest.org/en/stable/how-to/usage.html#profiling-test-execution-duration)

### Should I cache dependencies or split the tests?

Look at the slow step. A wheel cache avoids downloading Python packages again, but each job still installs them. If pytest itself takes most of the time, splitting the tests lets the two jobs work in parallel.

[GitHub: dependency caching](https://docs.github.com/en/actions/reference/workflows-and-actions/dependency-caching)

## Run this job on Checklane

Allow enough [runner capacity](https://checklane.sh/docs/runners) for both shards at once. If one waits until the other finishes, splitting the suite adds a second setup without overlapping the tests.

[Connect your repository](https://checklane.sh/docs/moving), then set the job’s runner label:

```
runs-on: checklane
```

---

From https://checklane.sh/guides/split-tests-github-actions-matrix
