diff --git a/changelog/5782.bugfix.rst b/changelog/5782.bugfix.rst new file mode 100644 index 000000000..e961d8fb5 --- /dev/null +++ b/changelog/5782.bugfix.rst @@ -0,0 +1 @@ +Fix decoding error when printing an error response from ``--pastebin``. 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): 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"