Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch httpretty socket for latest urllib3 release #3102

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Patch httpretty socket for latest urllib3 release
  • Loading branch information
EnricoMi committed Dec 28, 2024
commit 10a7135a04f71e6101f8b013aded8a662d08fd1f
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
Loading