diff --git a/AUTHORS b/AUTHORS index 6288f8c1b02..aa2237c6837 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 00000000000..fb7527d9960 --- /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 0cd3ce60427..c79bfeef024 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -424,7 +424,7 @@ def write(self, obj): 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 27f8d7d56e7..7d459e91c75 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1492,3 +1492,8 @@ def test_fails(): 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