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:
+6
-2
@@ -4,6 +4,8 @@ Mocks api_request and credentials.
|
||||
"""
|
||||
import sys
|
||||
import unittest
|
||||
import io
|
||||
import contextlib
|
||||
from unittest.mock import patch
|
||||
|
||||
sys.path.insert(0, str(__import__("pathlib").Path(__file__).resolve().parent.parent))
|
||||
@@ -24,14 +26,16 @@ class TestListPRs(unittest.TestCase):
|
||||
mock_api.return_value = [
|
||||
{"number": 1, "title": "PR 1", "head": {"ref": "branch1"}, "base": {"ref": "main"}, "html_url": "http://url1", "mergeable": True}
|
||||
]
|
||||
rc = list_prs.main([])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = list_prs.main([])
|
||||
self.assertEqual(rc, 0)
|
||||
mock_api.assert_called_once()
|
||||
|
||||
@patch("list_prs.api_request", return_value=[])
|
||||
@patch("list_prs.get_auth_header", return_value=FAKE_CREDS)
|
||||
def test_list_prs_empty(self, _auth, mock_api):
|
||||
rc = list_prs.main(["--state", "closed"])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = list_prs.main(["--state", "closed"])
|
||||
self.assertEqual(rc, 0)
|
||||
mock_api.assert_called_once()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user