Skip to content

Use specific exit status for pytest test failures be able to retry infra failures - #7611

Open
nccatoni wants to merge 4 commits into
mainfrom
nccatoni/test-fail-exit-code
Open

Use specific exit status for pytest test failures be able to retry infra failures#7611
nccatoni wants to merge 4 commits into
mainfrom
nccatoni/test-fail-exit-code

Conversation

@nccatoni

Copy link
Copy Markdown
Collaborator

Motivation

Changes

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

🛟 #apm-shared-testing 🛟

Reviewer checklist

  • Anything but tests/ or manifests/ is modified ? I have the approval from R&P team
  • A docker base image is modified?
    • the relevant build-XXX-image label is present
  • A scenario is added, removed or renamed?

@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

conftest.py                                                             @DataDog/system-tests-core
tests/test_the_test/test_junit.py                                       @DataDog/system-tests-core
tests/test_the_test/test_strict.py                                      @DataDog/system-tests-core
utils/ci/gitlab/system-tests.yml.j2                                     @DataDog/system-tests-core

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Aug 28, 2026

Copy link
Copy Markdown

Pipelines  Tests

Unblock PR with BitsAI

⚠️ Warnings

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 5 Pipeline jobs failed

DataDog/system-tests | Ubuntu_24_10_amd64.CON: [test-app-java-container] — 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

Test Nix | Test Nix (aarch64-linux) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

2 failed tests due to assertion errors; expected return code 42 but received 1 in tests/test_the_test/test_junit.py

Test Nix | Test Nix (x86_64-linux) — 🔧 Needs a code fix, caused by this PR

View more details · View in GitHub Actions

2 failed tests due to assertion errors: expected return code 42 but got 1.

View all 5 failed jobs.

📋 Copy fix prompt
CI on my pull request is failing. Help me find and fix the root cause of each failing job below — they were flagged as caused by changes in this PR, so focus on the diff. For each job, explain the failure and propose a fix.

Before you start, set up the Datadog software-delivery tooling so you can
query the CI data yourself:

1. Check whether you already have the Datadog software-delivery MCP tools
   (e.g. a `search_datadog_ci_pipeline_events` tool) and the `unblock-pr` skill.
2. If either is missing, STOP and ask me for permission before installing
   anything. Do not install or run anything until I have said yes.
3. Only with my explicit approval, set up the Datadog software-delivery MCP
   server and skills by following:
     https://docs.datadoghq.com/getting_started/software_delivery_mcp_tools/
   then restart so the skill is picked up.
4. If I decline, skip all of the above and work from the context below alone.

Then run /unblock-pr — it will pull the CI data itself. The job context below is what we already know.

If /unblock-pr is not available — because I declined the setup above, or it did not install — work from the context below instead.

Datadog has already classified this failure as caused by changes in this PR.
Take that as given and work the fix:

1. Locate the change. Diff this branch against its base and find the change
   that produces this error. Explain the mechanism, don't just name a file:
     git fetch origin && git diff $(git merge-base origin/main HEAD)...HEAD
2. Reproduce it locally. Run the failing job's command or test before
   proposing anything.
3. Propose the smallest fix that addresses the root cause — not a workaround,
   not a broadened assertion, not a disabled or skipped test.
4. Re-run the same command to confirm, and say exactly what you ran.
5. If the failure turns out to be intermittent rather than deterministic, say
   so plainly instead of "fixing" it — that is a flaky test, and patching it
   hides the problem.

If the right move is to re-run the job rather than change code, use the job
link in the context below. For GitHub Actions: `gh run rerun <run-id> --failed`,
where the run ID is the number after `/runs/` in that URL (not the trailing
number, which is the job ID).

Branch: nccatoni/test-fail-exit-code

Test Nix | Test Nix (aarch64-linux)
Commit: 30db24594dd44220e7d594c003bca480d5ccaa46
Error (code / test):
2 failed tests due to assertion errors; expected return code 42 but received 1 in tests/test_the_test/test_junit.py
CI job: https://github.com/DataDog/system-tests/actions/runs/33168777509/job/98840510702

Test Nix | Test Nix (x86_64-linux)
Commit: 30db24594dd44220e7d594c003bca480d5ccaa46
Error (code / test):
2 failed tests due to assertion errors: expected return code 42 but got 1.
CI job: https://github.com/DataDog/system-tests/actions/runs/33168777509/job/98840510717

Plus 1 more failing job not shown here.

ℹ️ Info

No other issues found (see more)

🧪 All tests passed
❄️ No new flaky tests detected

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 30db245 | Docs | View more details | Give us feedback!

@nccatoni
nccatoni marked this pull request as ready for review August 28, 2026 09:50
@nccatoni
nccatoni requested a review from a team as a code owner August 28, 2026 09:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6f88082fad

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread utils/ci/gitlab/system-tests.yml.j2 Outdated
Comment on lines +58 to +59
- 1-41
- 43-255

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Replace unsupported exit-code ranges

For every nonempty generated child pipeline, YAML parses 1-41 and 43-255 as strings, but GitLab's retry:exit_codes documentation permits a single integer exit code or an array of integer exit codes, not range expressions. GitLab therefore rejects the generated configuration before its jobs can run; enumerate the desired codes or restructure the retry logic instead.

Useful? React with 👍 / 👎.

Comment thread conftest.py Outdated
Comment on lines +572 to +573
if exitstatus == pytest.ExitCode.TESTS_FAILED:
session.exitstatus = TEST_FAIL_EXIT_CODE

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve retryability for fixture infrastructure errors

When infrastructure fails while a pytest fixture is starting or stopping, pytest also returns ExitCode.TESTS_FAILED; for example, the PARAMETRIC jobs create agent and library containers inside fixtures at tests/parametric/conftest.py:115-145, so a transient Docker error there produces a setup/teardown error with exit code 1. This hook converts that error to 42, which the new GitLab retry policy deliberately excludes, so precisely those infrastructure failures are not retried; only call-phase test failures should receive the special code.

Useful? React with 👍 / 👎.

@cbeauchesne cbeauchesne left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment on slack : If a scenario fails to start because of an failed healthcheck, will it be retried ? If yes, it's a red flag.

Basically, retry are authorized, if and only if :

  • the fail reason is perfectly identified
  • and it is absolutely outside of tested components scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants