def test_error_during_readouterr(pytester: Pytester) -> None:
    """Make sure we suspend capturing if errors occur during readouterr"""
    pytester.makepyfile(
        pytest_xyz="""
        from _pytest.capture import FDCapture

        def bad_snap(self):
            raise Exception('boom')

        assert FDCapture.snap
        FDCapture.snap = bad_snap
    """
    )
    result = pytester.runpytest_subprocess("-p", "pytest_xyz", "--version")
    result.stderr.fnmatch_lines(
        ["*in bad_snap", "    raise Exception('boom')", "Exception: boom"]
    )
Make sure we suspend capturing if errors occur during readouterr
testing/test_capture.py