Skip to content

Commit 814dfde

Browse files
committed
Re-harden test_typeerror_encodedfile_write
Changed in 60ceec6. This ensures the crash gets reported for the `sys.stdout.write`.
1 parent e3cf4fc commit 814dfde

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

testing/test_capture.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -1533,20 +1533,35 @@ def test_capture({0}):
15331533

15341534

15351535
def test_typeerror_encodedfile_write(testdir):
1536-
"""It should behave the same with and without output capturing (#4861)."""
1536+
"""It should behave the same with and without output capturing (#4861).
1537+
1538+
The reported location differs however.
1539+
"""
15371540
p = testdir.makepyfile(
15381541
"""
15391542
def test_fails():
15401543
import sys
15411544
sys.stdout.write(b"foo")
15421545
"""
15431546
)
1544-
result_without_capture = testdir.runpytest("-s", str(p))
15451547
result_with_capture = testdir.runpytest(str(p))
1546-
1547-
assert result_with_capture.ret == result_without_capture.ret
15481548
result_with_capture.stdout.fnmatch_lines(
1549-
["E * TypeError: write() argument must be str, not bytes"]
1549+
[
1550+
'> sys.stdout.write(b"foo")',
1551+
"> raise TypeError*",
1552+
"E TypeError: write() argument must be str, not bytes",
1553+
"FAILED test_typeerror_encodedfile_write.py:3::test_fails"
1554+
" - TypeError: write() argument must be str, not bytes",
1555+
]
1556+
)
1557+
result_without_capture = testdir.runpytest("-s", str(p))
1558+
result_without_capture.stdout.fnmatch_lines(
1559+
[
1560+
'> sys.stdout.write(b"foo")',
1561+
"E TypeError: write() argument must be str, not bytes",
1562+
"FAILED test_typeerror_encodedfile_write.py:3::test_fails"
1563+
" - TypeError: write() argument must be str, not bytes",
1564+
]
15501565
)
15511566

15521567

0 commit comments

Comments
 (0)