diff --git a/AUTHORS b/AUTHORS index 6288f8c1b..aa2237c68 100644 --- a/AUTHORS +++ b/AUTHORS @@ -256,6 +256,7 @@ Tim Hoffmann Tim Strazny Tom Dalton Tom Viner +Tomáš Gavenčiak Tomer Keren Trevor Bekolay Tyler Goodlet diff --git a/changelog/6557.bugfix.rst b/changelog/6557.bugfix.rst new file mode 100644 index 000000000..fb7527d99 --- /dev/null +++ b/changelog/6557.bugfix.rst @@ -0,0 +1 @@ +Make capture output streams ``.write()`` method return the same return value from original streams. diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 0cd3ce604..c79bfeef0 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -424,7 +424,7 @@ class EncodedFile: raise TypeError( "write() argument must be str, not {}".format(type(obj).__name__) ) - self.buffer.write(obj) + return self.buffer.write(obj) def writelines(self, linelist): data = "".join(linelist) diff --git a/testing/test_capture.py b/testing/test_capture.py index 27f8d7d56..7d459e91c 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1492,3 +1492,8 @@ def test_typeerror_encodedfile_write(testdir): result_with_capture.stdout.fnmatch_lines( ["E * TypeError: write() argument must be str, not bytes"] ) + + +def test_stderr_write_returns_len(capsys): + """Write on Encoded files, namely captured stderr, should return number of characters written.""" + assert sys.stderr.write("Foo") == 3