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:
@@ -11,6 +11,7 @@ import json
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import contextlib
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
# The module under test lives in the repo root, not a package.
|
||||
@@ -38,7 +39,8 @@ class TestArgParsing(unittest.TestCase):
|
||||
@patch("create_issue.api_request", return_value={"number": 1, "html_url": "http://x/1"})
|
||||
@patch("create_issue.get_credentials", return_value=FAKE_CREDS)
|
||||
def test_minimal_args(self, _cred, _api):
|
||||
rc = create_issue.main(["--title", "Hello"])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = create_issue.main(["--title", "Hello"])
|
||||
self.assertEqual(rc, 0)
|
||||
|
||||
def test_missing_title_exits(self):
|
||||
@@ -50,7 +52,8 @@ class TestArgParsing(unittest.TestCase):
|
||||
@patch("create_issue.get_credentials", return_value=FAKE_CREDS)
|
||||
def test_remote_choices(self, _cred, _api):
|
||||
for remote in ("dadeschools", "prgs"):
|
||||
rc = create_issue.main(["--remote", remote, "--title", "X"])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = create_issue.main(["--remote", remote, "--title", "X"])
|
||||
self.assertEqual(rc, 0, f"--remote {remote} should be accepted")
|
||||
|
||||
def test_invalid_remote_exits(self):
|
||||
@@ -138,7 +141,8 @@ class TestAuthFailure(unittest.TestCase):
|
||||
|
||||
@patch("create_issue.get_credentials", return_value=("", ""))
|
||||
def test_no_credentials_returns_1(self, _cred):
|
||||
rc = create_issue.main(["--title", "T"])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = create_issue.main(["--title", "T"])
|
||||
self.assertEqual(rc, 1)
|
||||
|
||||
|
||||
@@ -152,7 +156,8 @@ class TestAPIError(unittest.TestCase):
|
||||
def test_api_error_returns_1(self, _cred):
|
||||
with patch("create_issue.api_request",
|
||||
side_effect=RuntimeError("HTTP 422: duplicate")):
|
||||
rc = create_issue.main(["--title", "Dup"])
|
||||
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
|
||||
rc = create_issue.main(["--title", "Dup"])
|
||||
self.assertEqual(rc, 1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user