Skip to content

Commit

Permalink
Patch httpretty socket for latest urllib3 release
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Dec 28, 2024
1 parent 3d84a47 commit 10a7135
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/Framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
from typing import Optional

import httpretty # type: ignore
import urllib3
from packaging.version import Version
from requests.structures import CaseInsensitiveDict
from urllib3.util import Url # type: ignore

Expand All @@ -87,6 +89,22 @@
"""


# patch httpretty against urllib3>=2.3.0 https://github.com/PyGithub/PyGithub/issues/3101
if Version(urllib3.__version__) >= Version("2.3.0"):
getattr = httpretty.core.fakesock.socket.__getattr__

def patched_getattr(self, name):
def shutdown(how: int):
pass

if name == "shutdown" and not httpretty.core.httpretty.allow_net_connect and not self.truesock:
return shutdown

return getattr(self, name)

httpretty.core.fakesock.socket.__getattr__ = patched_getattr


def readLine(file_):
line = file_.readline()
if isinstance(line, bytes):
Expand Down

0 comments on commit 10a7135

Please sign in to comment.