Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): split product test shards by file (#104858)

Raúl Negrón-Oteroc0bd23a7e0c0
diff --git a/.github/scripts/turbo-discover-sizing.test.js b/.github/scripts/turbo-discover-sizing.test.js
index 6ba450e302be..028a25baf2ec 100644
--- a/.github/scripts/turbo-discover-sizing.test.js
+++ b/.github/scripts/turbo-discover-sizing.test.js
@@ -207,7 +207,17 @@ test("a split product's last shard absorbs a small product without leaking split
const shared = matrix.find((entry) => entry.group.includes('small-one'))
assert.equal(shared.group, 'big-one (2/2), small-one')
assert.equal(shared.legs.length, 2)
- assert.match(shared.legs[0].pytest_args, /--splits 2 --group 2/)
+ // Both shards split by file, so neither collects the other's test files.
+ assert.deepEqual(
+ matrix
+ .flatMap((entry) => entry.legs)
+ .filter((leg) => leg.filters === '--filter=@posthog/products-big-one')
+ .map((leg) => leg.pytest_args),
+ [
+ '-- --splits 2 --group 1 --splitting-algorithm optimal_chunks --split-granularity file',
+ '-- --splits 2 --group 2 --splitting-algorithm optimal_chunks --split-granularity file',
+ ]
+ )
// The whole product runs in its own leg, so it never sees --splits/--group.
assert.equal(shared.legs[1].filters, '--filter=@posthog/products-small-one')
assert.equal(shared.legs[1].pytest_args, '')
diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.js
index a788650d1348..9a21e8aeb249 100644
--- a/.github/scripts/turbo-discover.js
+++ b/.github/scripts/turbo-discover.js
@@ -1312,11 +1312,13 @@ function buildMatrix(products, durations, productsScaled = false) {
// optimally. The greedy rule in duration_based_chunks lets every shard
// overrun the per-shard average, which on skewed suites starves trailing
// shards down to zero tests (pytest exit 5, "no tests collected").
+ // File granularity keeps that balance but skips the other shards' test files
+ // before pytest imports them, so a shard collects only its own share.
const shardCost = work / shards + maxTest
for (let i = 1; i <= shards; i++) {
const leg = {
filters,
- pytest_args: `-- --splits ${shards} --group ${i} --splitting-algorithm optimal_chunks`,
+ pytest_args: `-- --splits ${shards} --group ${i} --splitting-algorithm optimal_chunks --split-granularity file`,
}
// work/shards + maxTest bounds every shard, whichever one
// optimal_chunks leaves lightest, so one shard can be offered to the
diff --git a/pyproject.toml b/pyproject.toml
index 8938aa388eb4..a7620d83ae1f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -323,7 +323,7 @@ infi-clickhouse-orm = { git = "https://github.com/PostHog/infi.clickhouse_orm",
# optimal_chunks split. Fork: PostHog/pytest-split (of jerry-git/pytest-split).
# To pull upstream fixes: rebase the fork's feat branch onto upstream, cut the next
# v0.11.0-posthog.N tag, and bump this pin.
-pytest-split = { git = "https://github.com/PostHog/pytest-split", tag = "v0.11.0-posthog.6" }
+pytest-split = { git = "https://github.com/PostHog/pytest-split", tag = "v0.11.0-posthog.7" }
# xgboost's Linux wheel declares nvidia-nccl-cu12 (322 MB) for multi-GPU training. We use xgboost on
# CPU, so drop it to keep the wheel out of the image.
diff --git a/uv.lock b/uv.lock
index 571b7c354a91..890736a07d80 100644
--- a/uv.lock
+++ b/uv.lock
@@ -6127,7 +6127,7 @@ dev = [
{ name = "pytest-icdiff", specifier = "~=0.9" },
{ name = "pytest-mock", specifier = "~=3.15.1" },
{ name = "pytest-rerunfailures", specifier = "~=16.1" },
- { name = "pytest-split", git = "https://github.com/PostHog/pytest-split?tag=v0.11.0-posthog.6" },
+ { name = "pytest-split", git = "https://github.com/PostHog/pytest-split?tag=v0.11.0-posthog.7" },
{ name = "pytest-timeout", specifier = "~=2.4.0" },
{ name = "pytest-xdist", specifier = "~=3.8.0" },
{ name = "python-dateutil", specifier = "~=2.9.0" },
@@ -6946,7 +6946,7 @@ wheels = [
[[package]]
name = "pytest-split"
version = "0.11.0"
-source = { git = "https://github.com/PostHog/pytest-split?tag=v0.11.0-posthog.6#8fc59b2e1ca13b9421f6e7828105d8635437c912" }
+source = { git = "https://github.com/PostHog/pytest-split?tag=v0.11.0-posthog.7#17ee53be4aaa2f27012da31b69656b4b45881cd5" }
dependencies = [
{ name = "pytest" },
]