diff --git a/testing/test_capture.py b/testing/test_capture.py index 7396fd26076..978981e0093 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1533,7 +1533,10 @@ 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(): @@ -1541,12 +1544,26 @@ def test_fails(): 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 - *", + ] )