Skip to content

Commit 9859d37

Browse files
authored
Merge pull request #5782 from linchiwei123/patch-1
Fix TypeError
2 parents 4265ab3 + 1c7aeb6 commit 9859d37

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

changelog/5782.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix decoding error when printing an error response from ``--pastebin``.

src/_pytest/pastebin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def create_new_paste(contents):
7272
if m:
7373
return "{}/show/{}".format(url, m.group(1))
7474
else:
75-
return "bad response: " + response
75+
return "bad response: " + response.decode("utf-8")
7676

7777

7878
def pytest_terminal_summary(terminalreporter):

testing/test_pastebin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@ def test_create_new_paste(self, pastebin, mocked_urlopen):
116116
assert "lexer=%s" % lexer in data.decode()
117117
assert "code=full-paste-contents" in data.decode()
118118
assert "expiry=1week" in data.decode()
119+
120+
def test_create_new_paste_failure(self, pastebin, monkeypatch):
121+
import io
122+
import urllib.request
123+
124+
def response(url, data):
125+
stream = io.BytesIO(b"something bad occurred")
126+
return stream
127+
128+
monkeypatch.setattr(urllib.request, "urlopen", response)
129+
result = pastebin.create_new_paste(b"full-paste-contents")
130+
assert result == "bad response: something bad occurred"

0 commit comments

Comments
 (0)