Skip to content

Comments

swev-id: pytest-dev__pytest-7521 preserve CR in capfd#36

Open
casey-brooks wants to merge 1 commit intopytest-dev__pytest-7521from
fix/capfd-preserve-cr
Open

swev-id: pytest-dev__pytest-7521 preserve CR in capfd#36
casey-brooks wants to merge 1 commit intopytest-dev__pytest-7521from
fix/capfd-preserve-cr

Conversation

@casey-brooks
Copy link

Summary

  • disable universal newline translations in FDCaptureBinary to preserve carriage returns
  • add regression tests for stdout/stderr CR and CRLF handling

Issue

Regression

  • Regression introduced in 29e4cb5
  • Reproducer:
def test_capfd_includes_carriage_return(capfd):
    print("Greetings from DOS", end="\r")
    out, err = capfd.readouterr()
    assert out.endswith("\r")
  • Failure before fix:
$ PYTHONPATH=src PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_ADDOPTS=--assert=plain python -m pytest -q testing/test_capture_capfd_cr.py::test_capfd_includes_carriage_return
F                                                                        [100%]
=================================== FAILURES ===================================
_____________________ test_capfd_includes_carriage_return ______________________

capfd = <_pytest.capture.CaptureFixture object at 0xffff9286a150>

    def test_capfd_includes_carriage_return(capfd):
        print('Greetings from DOS', end='\r')
        out, err = capfd.readouterr()
>       assert out.endswith('\r')
E       AssertionError

testing/test_capture_capfd_cr.py:4: AssertionError
=========================== short test summary info ============================
FAILED testing/test_capture_capfd_cr.py::test_capfd_includes_carriage_return
1 failed in 0.02s

Testing

  • PYTHONPATH=src PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_ADDOPTS=--assert=plain python -m pytest -q testing/test_capture_capfd_cr.py
  • flake8 --extend-ignore=F821 src/_pytest/capture.py testing/test_capture_capfd_cr.py

@casey-brooks casey-brooks requested a review from a team December 25, 2025 21:15
@casey-brooks
Copy link
Author

Local verification:\n- PYTHONPATH=src PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_ADDOPTS=--assert=plain python -m pytest -q testing/test_capture_capfd_cr.py (3 passed)\n- flake8 --extend-ignore=F821 src/_pytest/capture.py testing/test_capture_capfd_cr.py (no lint issues)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix looks correct: disabling universal newline translation in FDCaptureBinary preserves CR/CRLF and the new regression tests cover stdout/stderr paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants