Preserve newlines when captured with capfd

This commit is contained in:
Anthony Sottile 2020-07-20 08:54:20 -07:00
parent 41d211c24a
commit 8616a5f1d9
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(
"""\