From a4adf511fc1e275880c7c4bd68c376eab3435437 Mon Sep 17 00:00:00 2001 From: linchiwei123 <40888469+linchiwei123@users.noreply.github.com> Date: Sat, 24 Aug 2019 20:49:00 +0800 Subject: [PATCH 1/3] Fix TypeError can only concatenate str (not "bytes") to str --- changelog/5782.bugfix.rst | 1 + src/_pytest/pastebin.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/5782.bugfix.rst diff --git a/changelog/5782.bugfix.rst b/changelog/5782.bugfix.rst new file mode 100644 index 000000000..d1f144b21 --- /dev/null +++ b/changelog/5782.bugfix.rst @@ -0,0 +1 @@ +Fix decoding error when printing an error response from ``--pastebin``. \ No newline at end of file diff --git a/src/_pytest/pastebin.py b/src/_pytest/pastebin.py index ce0e73acc..91aa5f1fd 100644 --- a/src/_pytest/pastebin.py +++ b/src/_pytest/pastebin.py @@ -72,7 +72,7 @@ def create_new_paste(contents): if m: return "{}/show/{}".format(url, m.group(1)) else: - return "bad response: " + response + return "bad response: " + response.decode("utf-8") def pytest_terminal_summary(terminalreporter): From 691c706fcc27e4765bdb49b3e3bdf9a95e2bf283 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 24 Aug 2019 14:41:06 -0300 Subject: [PATCH 2/3] Add test for #5782 --- testing/test_pastebin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py index 9afa1e23f..4e8bac56c 100644 --- a/testing/test_pastebin.py +++ b/testing/test_pastebin.py @@ -116,3 +116,15 @@ class TestPaste: assert "lexer=%s" % lexer in data.decode() assert "code=full-paste-contents" in data.decode() assert "expiry=1week" in data.decode() + + def test_create_new_paste_failure(self, pastebin, monkeypatch): + import io + import urllib.request + + def response(url, data): + stream = io.BytesIO(b"something bad occurred") + return stream + + monkeypatch.setattr(urllib.request, "urlopen", response) + result = pastebin.create_new_paste(b"full-paste-contents") + assert result == "bad response: something bad occurred" From 1c7aeb670af879f0b50d991da15e61d69ac17dab Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 24 Aug 2019 15:01:48 -0300 Subject: [PATCH 3/3] Fix linting --- changelog/5782.bugfix.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/5782.bugfix.rst b/changelog/5782.bugfix.rst index d1f144b21..e961d8fb5 100644 --- a/changelog/5782.bugfix.rst +++ b/changelog/5782.bugfix.rst @@ -1 +1 @@ -Fix decoding error when printing an error response from ``--pastebin``. \ No newline at end of file +Fix decoding error when printing an error response from ``--pastebin``.