: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(ci): name failing tests in the django gate (#70815)
Raúl Negrón-Otero27dbe1b17f97
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 241072b0a4ee..a6429f52e62a 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -21,6 +21,10 @@# Trunk posting from a non-blocking timing trial — and so also omits the test# steps' continue-on-error and that verdict step, letting each shard's test# exit code be the verdict directly)+# - Per-test failure rollup: canonical's django_tests gate uploads product JUnit and, when a+# test job fails, downloads that shard's JUnit to list the actual failing tests. The shadow+# strips artifact uploads (above), so it has nothing to download and keeps the plain+# dependency-result table — depot-exempt for the same reason as the other uploads.# - OpenAPI types: the check-openapi-types job is folded into check-migrations as a# check-only step (drift still fails the run); only its auto-commit side effect is dropped# - actions/cache reads/writes route to Depot Cache, not GitHub Actions Cache,diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.ymlindex e5e058b58fb0..e4e5d43080f4 100644--- a/.github/workflows/ci-backend.yml+++ b/.github/workflows/ci-backend.yml@@ -843,6 +843,29 @@ jobs:shell: bashrun: exit 1+ # Feeds the django_tests gate's per-test failure rollup. Rename each file to carry+ # its product so the name survives upload-artifact's least-common-ancestor path+ # collapse (same trick as "Stage product coverage" below).+ - name: Stage product JUnit+ if: always()+ shell: bash+ run: |+ mkdir -p junit-staging+ for f in products/*/junit-product.xml; do+ [ -f "$f" ] || continue+ cp "$f" "junit-staging/junit-product-$(basename "$(dirname "$f")").xml"+ done+ # Separate prefix from junit-results-backend-* on purpose: those are consumed by+ # test-selection-verdict (snob shadow) and report-test-timings, not product tests.+ - name: Upload product test results+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0+ if: always()+ with:+ name: product-junit-results-${{ strategy.job-index }}+ path: junit-staging/junit-product-*.xml+ if-no-files-found: ignore+ overwrite: true # artifacts are immutable per run; re-run shards would 409 otherwise+- name: Upload timing datauses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0if: ${{ github.ref == 'refs/heads/master' }}@@ -2919,7 +2942,8 @@ jobs:]name: Django Tests Passruns-on: ubuntu-latest- timeout-minutes: 5+ # Headroom for downloading every shard's JUnit for the failure rollup.+ timeout-minutes: 8if: always()steps:- name: Summarize dependency results@@ -2948,8 +2972,82 @@ jobs:fi} | tee -a "$GITHUB_STEP_SUMMARY"+ # Per-test failure rollup: only when a test job actually failed, download that+ # shard's JUnit so "Check dependency results" can list the failing tests. Skipped+ # on green runs (the common case) to avoid pulling ~50 artifacts for nothing.+ # continue-on-error so a flaky fetch can't fail this required gate.+ - name: Download shard JUnit results+ if: always() && (needs.django.result != 'success' || needs.turbo-tests.result != 'success')+ continue-on-error: true+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0+ with:+ pattern: '{junit-results-backend,product-junit-results}-*'+ path: /tmp/junit-gate/- name: Check dependency resultsrun: |+ # Per-test failure rollup, emitted from THIS step because GitHub only+ # auto-expands the failed step in the log view. Best-effort via `|| true`+ # so a parser hiccup never changes the verdict computed below.+ python3 <<'PY' || true+ import glob, os, xml.etree.ElementTree as ET++ ROOT = "/tmp/junit-gate"+ rows = [] # (shard, nodeid, repo_file, message)++ def clean(s):+ # Collapse newlines so PR-authored test names can't inject ::workflow-commands::+ return " ".join((s or "").split())++ for path in glob.glob(os.path.join(ROOT, "**", "junit-*.xml"), recursive=True):+ artifact = os.path.relpath(path, ROOT).split(os.sep)[0]+ base = os.path.basename(path)+ # Product JUnit is staged as junit-product-<name>.xml; backend keeps its key.+ product = base[len("junit-product-"):-len(".xml")] if base.startswith("junit-product-") else ""+ shard = f"products/{product}" if product else artifact.removeprefix("junit-results-backend-")+ with open(path, "rb") as fh:+ raw = fh.read()+ # Refuse DTD/entity payloads (XXE, billion-laughs). pytest JUnit has neither,+ # so real failures are never dropped; a crafted file is simply skipped.+ if b"<!DOCTYPE" in raw or b"<!ENTITY" in raw:+ continue+ try:+ tree = ET.fromstring(raw)+ except ET.ParseError:+ continue+ for tc in tree.iter("testcase"):+ bad = tc.find("failure")+ if bad is None:+ bad = tc.find("error")+ if bad is None:+ continue+ name = tc.get("name", "")+ file_ = tc.get("file", "") or tc.get("classname", "")+ repo_file = f"products/{product}/{file_}" if product and file_ else file_+ nodeid = clean("::".join(p for p in (repo_file, name) if p))+ msg = clean(bad.get("message") or bad.text or "")[:200]+ rows.append((clean(shard), nodeid, clean(repo_file), msg))++ # Print only when something failed; on a green gate this stays silent.+ if rows:+ out = ["### Failing backend & product tests", "", f"{len(rows)} failing test(s):",+ "", "| Shard | Test | Message |", "| --- | --- | --- |"]+ for shard, nodeid, _f, msg in rows[:100]:+ out.append(f"| {shard} | `{nodeid.replace('|', r'\|')}` | {msg.replace('|', r'\|')} |")+ if len(rows) > 100:+ out += ["", f"…and {len(rows) - 100} more."]+ text = "\n".join(out) + "\n"+ summary = os.environ.get("GITHUB_STEP_SUMMARY")+ if summary:+ with open(summary, "a") as fh:+ fh.write(text)+ print(text)+ for shard, nodeid, repo_file, msg in rows[:30]:+ title = f"Backend test failed ({shard})"+ body = f"{nodeid}: {msg}" if msg else nodeid+ loc = f"file={repo_file}," if repo_file else ""+ print(f"::error {loc}title={title}::{body}")+ PY+deterministic_failure=falsefailed=false