test: isolate CLI output capture with monkeypatch/redirect to fix stdout corruption in full suite runs (Issue #178)
- Replace raw patch("sys.stdout") and contextlib.redirect_stderr with pytest MonkeyPatch or contextlib redirect scoped to main calls in CLI tests (create_*, prs, python_cli, manage_labels, merge_pr, review_pr).
- Add regression tests in test_review_proofs.py for stdout/stderr remaining usable.
- Ensures normal pytest summary output without junitxml workaround; improves review validation reporting per #173.
- No behavior change to production code or gates.
Refs #178
This commit is contained in:
@@ -45,13 +45,17 @@ class TestMergeDisabled(unittest.TestCase):
|
||||
mock_api.assert_not_called()
|
||||
|
||||
def test_message_points_to_gated_workflow(self):
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
import io
|
||||
import contextlib
|
||||
with patch("merge_pr.get_auth_header", return_value=FAKE_CREDS), \
|
||||
patch("merge_pr.api_request") as mock_api:
|
||||
buf = io.StringIO()
|
||||
with contextlib.redirect_stderr(buf):
|
||||
monkeypatch = MonkeyPatch()
|
||||
monkeypatch.setattr(sys, "stderr", buf)
|
||||
try:
|
||||
rc = merge_pr.main(["--pr-number", "81"])
|
||||
finally:
|
||||
monkeypatch.undo()
|
||||
self.assertEqual(rc, 2)
|
||||
mock_api.assert_not_called()
|
||||
msg = buf.getvalue().lower()
|
||||
|
||||
Reference in New Issue
Block a user