Important note on where to patch for mocking unit tests.
You can't patch the lib like @patch("urllib.request.urlopen") because the class already has the reference to the actual urlopen function. You need to patch the class's reference to urlopen. Example:
MOCK_RESPONSE = "{hello: world}".encode() @patch("my_proj.my_file.urlopen") def test_load_url(self, mock_urlopen): mock_urlopen.return_value = BytesIO(self.MOCK_RESPONSE) loader = UrlLoader("https://fake.url/build/5") assert loader.data == {"hello": "world"}










