Skip to content

CICD-043 · Split pytest by stable file set ​

Encyclopedia · Matrices and sharding · All snippets

Previous · CICD-042 · Next · CICD-044

1. Where it fits ​

  • Placement Bash run step following checkout, or equivalent lab terminal.
  • Prerequisites workspace whose runtime dependencies match the chosen target combinations.
  • Platforms local-linux, github-actions, gitea-actions.
  • Parameters SHARD.

2. Copy the snippet ​

bash
git ls-files 'tests/test_*.py' | sort > tests.txt
mapfile -t selected < <(awk -v part="${SHARD:?}" '((NR-1)%4)==part' tests.txt)
test "${#selected[@]}" -gt 0 && pytest -q "${selected[@]}"

3. How it works ​

The sorted file list is assigned to shards using its zero-based row number modulo four. The nonempty test prevents a bad shard choice from producing a green no-op.

4. Verify the result ​

Set SHARD from 0 through 3 and ensure one row contains every intended file exactly once. Use simple fixture filenames.

Validation syntax-validated (Bash parse). Status definitions.