Skip to content

tests/tap_runner: intercept stderr as TAP diagnostic lines#20

Draft
Copilot wants to merge 8 commits intomasterfrom
copilot/update-tap-runner-stderr-interception
Draft

tests/tap_runner: intercept stderr as TAP diagnostic lines#20
Copilot wants to merge 8 commits intomasterfrom
copilot/update-tap-runner-stderr-interception

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 7, 2026

  • Add TAPDiagnosticStream class that prefixes each line with # and writes to real_stdout
  • Replace sys.stdout = real_stderr with sys.stdout = TAPDiagnosticStream(real_stdout) so print() output goes to stdout as TAP diagnostic lines
  • Keep error/failure tracebacks going to stderr (actual errors, not logging)
Original prompt

Repo: igaw/nvme-cli

Goal: Update the TAP runner so that stderr from tests is also intercepted and re-emitted as TAP diagnostic lines, the same way stdout is currently handled.

Context

  • File to change: tests/tap_runner.py
  • Current behavior:
    • Writes TAP version 13 as the first line to the real stdout.
    • Replaces sys.stdout with DiagnosticCapture(real_stdout) so any print() output from tests becomes # ... diagnostic lines.
    • sys.stderr is not redirected, so writes to stderr can break TAP output parsing.

Requirements

  1. Intercept stderr as well as stdout during test execution.
  2. Re-emit intercepted stderr lines as TAP diagnostic lines (# ...) to the real stdout (or otherwise ensure TAP stream remains valid).
  3. Ensure the TAP version header remains the first line on stdout.
  4. Ensure streams are restored reliably even if tests raise errors/exceptions.
  5. Keep behavior compatible with unittest and Meson TAP parsing.

Implementation notes

  • Consider using DiagnosticCapture for both stdout and stderr, or implement a variant that tags source (optional).
  • Ensure partial lines are handled on flush like stdout is.
  • Ensure sys.stderr is flushed/restored correctly.

Please create a PR implementing this change.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: stderr should also be intercepted like stdout from the test.

Assistant: I’m ready to continue with the change, but I’m currently waiting for your approval in the tool-permission dialog before I can proceed.

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Update TAP runner to intercept stderr as TAP diagnostics tests/tap_runner: intercept stderr as TAP diagnostic lines Apr 7, 2026
Copilot AI requested a review from igaw April 7, 2026 15:48
Copilot finished work on behalf of igaw April 7, 2026 15:48
Instead of redirecting sys.stdout to real_stderr (which mixes logging
with error output), introduce TAPDiagnosticStream that prefixes every
print() line with '# ' and writes it to real_stdout.  This keeps
diagnostic logging on stdout as TAP-compliant diagnostic lines, while
error/failure tracebacks continue to go to stderr.

Resulting output:
  stdout: TAP version 13 / plan / # diagnostics / ok|not ok lines
  stderr: error tracebacks only

Agent-Logs-Url: https://github.com/igaw/nvme-cli/sessions/bfd8b019-7cb6-45ff-bf10-301d962076e4

Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
Copilot finished work on behalf of igaw April 8, 2026 07:45
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