diff --git a/AUTHORS b/AUTHORS index 0bee4a3d6..5eea42ea2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -261,6 +261,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/codecov.yml b/codecov.yml index a0a308588..db2472009 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,7 +1 @@ -coverage: - status: - project: true - patch: true - changes: true - comment: off diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 24072d34a..26b473bb0 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -427,7 +427,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/src/_pytest/main.py b/src/_pytest/main.py index 5a0de75c7..daaa4cea2 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -76,7 +76,7 @@ def pytest_addoption(parser): dest="maxfail", const=1, help="exit instantly on first error or failed test.", - ), + ) group._addoption( "--maxfail", metavar="num", @@ -123,7 +123,7 @@ def pytest_addoption(parser): "--co", action="store_true", help="only collect tests, don't execute them.", - ), + ) group.addoption( "--pyargs", action="store_true", diff --git a/testing/test_capture.py b/testing/test_capture.py index b68d81781..e0e38ea51 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1532,3 +1532,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