Merge pull request #7521 from asottile/newlines_unaffected

Preserve newlines when captured with capfd
This commit is contained in:
Anthony Sottile 2020-07-20 11:48:08 -07:00 committed by GitHub
commit 6ecb8f53d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -0,0 +1 @@
Preserve line endings when captured via ``capfd``.

View File

@ -388,6 +388,7 @@ class FDCaptureBinary:
TemporaryFile(buffering=0), # type: ignore[arg-type]
encoding="utf-8",
errors="replace",
newline="",
write_through=True,
)
if targetfd in patchsysdict:

View File

@ -514,6 +514,12 @@ class TestCaptureFixture:
)
reprec.assertoutcome(passed=1)
@pytest.mark.parametrize("nl", ("\n", "\r\n", "\r"))
def test_cafd_preserves_newlines(self, capfd, nl):
print("test", end=nl)
out, err = capfd.readouterr()
assert out.endswith(nl)
def test_capfdbinary(self, testdir):
reprec = testdir.inline_runsource(
"""\