Skip to content

Commit 266a6b7

Browse files
authored
Re-harden test_typeerror_encodedfile_write (#276)
Changed in 60ceec6. This ensures the crash gets reported for the `sys.stdout.write`.
1 parent 69919e8 commit 266a6b7

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

testing/test_capture.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,21 +1536,39 @@ def test_capture({0}):
15361536
assert result.ret == 0
15371537

15381538

1539+
@pytest.mark.pypy_specific
15391540
def test_typeerror_encodedfile_write(testdir):
1540-
"""It should behave the same with and without output capturing (#4861)."""
1541+
"""It should behave the same with and without output capturing (#4861).
1542+
1543+
The reported location differs however.
1544+
"""
15411545
p = testdir.makepyfile(
15421546
"""
15431547
def test_fails():
15441548
import sys
15451549
sys.stdout.write(b"foo")
15461550
"""
15471551
)
1548-
result_without_capture = testdir.runpytest("-s", str(p))
15491552
result_with_capture = testdir.runpytest(str(p))
1550-
1551-
assert result_with_capture.ret == result_without_capture.ret
15521553
result_with_capture.stdout.fnmatch_lines(
1553-
["E * TypeError: write() argument must be str, not bytes"]
1554+
[
1555+
'> sys.stdout.write(b"foo")',
1556+
" def write*",
1557+
"E TypeError: write() argument must be str, not bytes",
1558+
"FAILED test_typeerror_encodedfile_write.py:3::test_fails - *",
1559+
]
1560+
)
1561+
result_without_capture = testdir.runpytest("-s", str(p))
1562+
if getattr(sys, "pypy_version_info", None):
1563+
exp_exc = "TypeError: unicode argument expected, got 'bytes'"
1564+
else:
1565+
exp_exc = "TypeError: write() argument must be str, not bytes"
1566+
result_without_capture.stdout.fnmatch_lines(
1567+
[
1568+
'> sys.stdout.write(b"foo")',
1569+
"E " + exp_exc,
1570+
"FAILED test_typeerror_encodedfile_write.py:3::test_fails - *",
1571+
]
15541572
)
15551573

15561574

0 commit comments

Comments
 (0)