MCPcopy Create free account
hub / github.com/pytest-dev/pytest / mocked_urlopen_fail

Method mocked_urlopen_fail

testing/test_pastebin.py:92–104  ·  view source on GitHub ↗

Monkeypatch the actual urlopen call to emulate a HTTP Error 400.

(self, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

90
91 @pytest.fixture
92 def mocked_urlopen_fail(self, monkeypatch: MonkeyPatch):
93 """Monkeypatch the actual urlopen call to emulate a HTTP Error 400."""
94 calls = []
95
96 import urllib.error
97 import urllib.request
98
99 def mocked(url, data):
100 calls.append((url, data))
101 raise urllib.error.HTTPError(url, 400, "Bad request", {}, io.BytesIO())
102
103 monkeypatch.setattr(urllib.request, "urlopen", mocked)
104 return calls
105
106 @pytest.fixture
107 def mocked_urlopen_invalid(self, monkeypatch: MonkeyPatch):

Callers

nothing calls this directly

Calls 1

setattrMethod · 0.80

Tested by

no test coverage detected