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

Method mocked_urlopen_invalid

testing/test_pastebin.py:107–126  ·  view source on GitHub ↗

Monkeypatch the actual urlopen calls done by the internal plugin function that connects to bpaste service, but return a url in an unexpected format.

(self, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

105
106 @pytest.fixture
107 def mocked_urlopen_invalid(self, monkeypatch: MonkeyPatch):
108 """Monkeypatch the actual urlopen calls done by the internal plugin
109 function that connects to bpaste service, but return a url in an
110 unexpected format."""
111 calls = []
112
113 def mocked(url, data):
114 calls.append((url, data))
115
116 class DummyFile:
117 def read(self):
118 # part of html of a normal response
119 return b'View <a href="/invalid/3c0c6750bd">raw</a>.'
120
121 return DummyFile()
122
123 import urllib.request
124
125 monkeypatch.setattr(urllib.request, "urlopen", mocked)
126 return calls
127
128 @pytest.fixture
129 def mocked_urlopen(self, monkeypatch: MonkeyPatch):

Callers

nothing calls this directly

Calls 1

setattrMethod · 0.80

Tested by

no test coverage detected