# Pytest-split + github actions behavior

**URL:** <https://forum.buildkite.community/t/pytest-split-github-actions-behavior/4196>\
**Category:** General\
**Created:** [February 1, 2025, 5:37am UTC](https://forum.buildkite.community/t/pytest-split-github-actions-behavior/4196 "2025-02-01T05:37:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sshleifer](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@sshleifer](https://forum.buildkite.community/u/sshleifer)\
**Post date:** [February 1, 2025, 5:37am UTC](https://forum.buildkite.community/t/pytest-split-github-actions-behavior/4196/1 "2025-02-01T05:37:20Z")

</div>

I was trying to split my pytest suite (currently triggered via pipeline + buildkite-agent-k8s) in 2 parts.

Previously, I’ve used pytest-split in GitHub actions to accomplish this:

```auto
jobs:
  build:
    strategy:
      matrix:
        split: [1,2,3,4]
    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
    - name: Run 1/4 of the Tests
      run: |
	pip install pytest-split
        python -m pytest --splits 4 --group ${{ matrix.split }} --splitting-algorithm least_duration --store-durations tests/

```

What is the correct way to do it in build kite?

---

<div class="post-metadata">

**Author:** ![lizette](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/lizette/32/1161_2.png) [@lizette](https://forum.buildkite.community/u/lizette)\
**Post date:** [February 3, 2025, 4:06am UTC](https://forum.buildkite.community/t/pytest-split-github-actions-behavior/4196/2 "2025-02-03T04:06:33Z")

</div>

Hi @sshleifer ,

Here’s what the step would roughly be like in Buildkite:

```auto
steps:
  - name: "python test splitting"   
    commands:  
    - pip install pytest
    - pip install pytest-split
    - pytest -q projects/simplepytest/test_compare.py --splits 3 --group {{matrix}} --splitting-algorithm least_duration
    matrix:
    - 1
    - 2
    - 3
    plugins:
      - docker#v5.12.0:
          image: "python:latest"          

```

With the above steps, I used our [docker plugin](https://github.com/buildkite-plugins/docker-buildkite-plugin) to setup the test environment with pytest and pytest-split. I also used the [build matrix configuration](https://buildkite.com/docs/pipelines/configure/workflows/build-matrix) to expand the groups based on your example.

However, this does not have to be the case. You can read more about our [Test Suites](https://buildkite.com/docs/test-engine/test-suites#parallelized-builds) product and explore parallelising builds when configuring your step with [parallel jobs](https://buildkite.com/docs/pipelines/tutorials/parallel-builds#parallel-jobs).

In addition, when you wish to explore more about migrating more Github Actions to Buildkite Pipelines, you can explore our [migration tool](https://github.com/buildkite/migration/blob/main/docs/GHA.md). Hope this helps.

Cheers!
