From 5e15c86cc6fb800adf87e5eff0a36896b2cb895e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Gaven=C4=8Diak?= Date: Fri, 24 Jan 2020 13:50:56 +0100 Subject: [PATCH 1/3] Fix EncodedFile.write return value Make EncodedFile, used for captured output streams, method .write return the number of characters written. Add test for captured stderr write. Fixes #6557. Co-Authored-By: Bruno Oliveira --- AUTHORS | 1 + changelog/6557.bugfix.rst | 1 + src/_pytest/capture.py | 2 +- testing/test_capture.py | 5 +++++ 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/6557.bugfix.rst 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 From a29d6194f56cbd111a920035d1bf21c2daa0b23c Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 25 Jan 2020 11:14:00 +0100 Subject: [PATCH 2/3] ci: codecov: only use "comment: off" The changes status is quite buggy, remove it for now. This just uses "comment: off" then. --- codecov.yml | 6 ------ 1 file changed, 6 deletions(-) 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 From 94d8c071b62394ef7a51f75c109f57ddbe5052bd Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 25 Jan 2020 14:28:32 +0200 Subject: [PATCH 3/3] Remove a couple of redundant commas Mypy complains about this once the function is typed: src/_pytest/main.py:85: error: "_addoption" of "OptionGroup" does not return a value src/_pytest/main.py:133: error: "addoption" of "OptionGroup" does not return a value --- src/_pytest/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index ae115b1f8..7ce4c19ea 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -75,7 +75,7 @@ def pytest_addoption(parser): dest="maxfail", const=1, help="exit instantly on first error or failed test.", - ), + ) group._addoption( "--maxfail", metavar="num", @@ -122,7 +122,7 @@ def pytest_addoption(parser): "--co", action="store_true", help="only collect tests, don't execute them.", - ), + ) group.addoption( "--pyargs", action="store_true",