Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-harden test_typeerror_encodedfile_write #6876

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 22 additions & 5 deletions testing/test_capture.py
Expand Up @@ -1533,20 +1533,37 @@ def test_capture({0}):


def test_typeerror_encodedfile_write(testdir):
"""It should behave the same with and without output capturing (#4861)."""
"""It should behave the same with and without output capturing (#4861).

The reported location differs however.
"""
p = testdir.makepyfile(
"""
def test_fails():
import sys
sys.stdout.write(b"foo")
"""
)
result_without_capture = testdir.runpytest("-s", str(p))
result_with_capture = testdir.runpytest(str(p))

assert result_with_capture.ret == result_without_capture.ret
result_with_capture.stdout.fnmatch_lines(
["E * TypeError: write() argument must be str, not bytes"]
[
'> sys.stdout.write(b"foo")',
" def write*",
"E TypeError: write() argument must be str, not bytes",
"FAILED test_typeerror_encodedfile_write.py::test_fails - *",
]
)
result_without_capture = testdir.runpytest("-s", str(p))
if getattr(sys, "pypy_version_info", None):
exp_exc = "TypeError: unicode argument expected, got 'bytes'"
else:
exp_exc = "TypeError: write() argument must be str, not bytes"
result_without_capture.stdout.fnmatch_lines(
[
'> sys.stdout.write(b"foo")',
"E " + exp_exc,
"FAILED test_typeerror_encodedfile_write.py::test_fails - *",
]
)


Expand Down