Skip to content

fix(ci): fail-to-pass reports a replay pytest could not start as could-not-run - #1718

Merged
dan-petty merged 1 commit into
release/v0.2.37from
fix/1669-fail-to-pass-could-not-run
Oct 20, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.37from
fix/1669-fail-to-pass-could-not-run

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The second and last of #1669's pull requests. A fail-to-pass replay whose pytest could not run on the base tree is now reported as "could not run", not as "0 failed, 0 errored". With #1717, this completes #1669.

The defect. _run_pytest_on_base dropped pytest's exit status and returned no outcomes when the JUnit report was missing. So a replay that never started read as an empty, clean replay:

  • a feature pull request passed the check with nothing replayed;
  • a defect pull request failed it with the wrong reason, "requires at least one changed test to fail".

#1312 PR 3 (#1703) hit this: its replayed tests imported a name the base's src lacked.

The fix.

  • Exit status: _run_pytest_on_base keeps pytest's exit status.

  • What counts as "could not run":

    • an exit of 2 (interrupted), 3 (internal error) or 4 (usage error);
    • a run that wrote no complete JUnit report.

    It is recorded as ReplayCouldNotRun, with the exit status and the last whole lines of pytest's output that fit in 256 characters.

  • Exit 3 with a report: it still counts, since pytest writes a report holding pytest::internal when an internal error ends a session it had begun.

  • Broken reports: a report that is empty, or never closes its root testsuites element, counts as no report. The parser is still the stdlib HTMLParser and records whether the root closed.

  • The check: such a replay fails it for any pull request. The report names the exit status, the replayed files and pytest's last output, and points to Fail-to-pass: not applicable:, which still passes without replaying.

  • Unchanged: exit 5 (no tests collected) stays an empty replay. A replay whose tests collect and run reports as before, so a changed test that only fails to collect on base is reported as errored.

  • Output: an unsatisfied report is written raw, with markup and emoji codes off, so pytest's output reaches the terminal as written.

Records.

Verification

  • Tests first. The new cases failed against the base's fail_to_pass.py. Each review fix was shown failing against a planted mutant:
    • exit 3 dropped from the could-not-run set;
    • empty and truncated reports accepted;
    • emoji codes rendered;
    • the tail bound's off-by-one.
  • The issue's case, live. Replaying test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312 PR 3's branch against its base, the old code passed a feat title with "0 failed, 0 errored". This code exits 1 with "could not run on base: pytest exited with status 3", plus the ImportError line.
  • Review. An adversarial review, with each finding checked by a skeptic, drove the exit-3-with-report case, the broken-report rule, the narrowed AGENTS.md wording, the snapshots and the raw output.
  • Isolation. The full suite passed under a guard that refuses gh children: 11,089 passed, 1 skipped, 8 xfailed, and 10 snapshots passed.
  • Fail-to-pass. devops ci fail-to-pass --base origin/release/v0.2.37 on this branch: 13 changed tests fail on base, and 16 pass.
  • Gate. uv run devops ci passed (pre-push hook).

Closes #1669

…d-not-run

When pytest could not start on the replayed base tree, devops ci fail-to-pass reported "0 failed and 0 passed ...; 0 errored" as an outcome: a feature passed the check with nothing replayed, and a defect failed it saying no changed test failed on base, though none ran. _run_pytest_on_base dropped pytest's exit status and returned no outcomes when the JUnit report was missing.

_run_pytest_on_base now keeps pytest's exit status. An exit of 2 (interrupted), 3 (internal error) or 4 (usage error), or a run that wrote no complete JUnit report, is a ReplayCouldNotRun on the report, with the exit status and the last whole lines of pytest's output that fit in 256 characters. Exit 3 counts with a report too, as pytest writes one holding pytest::internal when an internal error ends a session it had begun to report. A report that is empty or never closes its root testsuites element counts as none: the JUnit parser, still the stdlib HTMLParser, records whether the root closed. Such a replay fails the check for any pull request; the report names the exit status, the replayed test files and pytest's last output, and points to the Fail-to-pass: not applicable line, which still passes the check without replaying. Exit 5, no tests collected, stays an empty replay, and a replay whose tests collect and run reports as before, so a changed test that only fails to collect on base is reported as errored. The command writes an unsatisfied report raw, with markup and emoji codes off, so pytest's output reaches the terminal as pytest wrote it.

AGENTS.md and the instruction generator's line say the check fails any pull request whose replay pytest could not run on base, as when the overlaid tests/ import support the base lacks or the pull request changes dependencies or the test harness; that such a pull request declares the not-applicable line; and that a changed test that only fails to collect on base is reported as errored. The could-not-run reports' text is checked against syrupy snapshots, the suite's first, which docs/TESTING.md now names; the trailing-whitespace hook leaves tests/__snapshots__/ alone, as trimming a blank line's indent breaks a snapshot.

With part 1 (#1717), the per-test timeout, the narrowed run's worker count and its process-group stop, this completes the item. The task file keeps part 1's section and adds this one as PR 2, with every criterion of the item and both amendments delivered, and changelog.d/1669.md is the item's one fragment, covering both parts.

Closes #1669
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.

1 participant