Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5782.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix decoding error when printing an error response from ``--pastebin``.
2 changes: 1 addition & 1 deletion src/_pytest/pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions testing/test_pastebin.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,15 @@ def test_create_new_paste(self, pastebin, mocked_urlopen):
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"