ensure all plugins are migrated to Niquests prior to importing them

This commit is contained in:
Ahmed TAHRI 2024-10-15 09:45:43 +02:00
parent 7537b40bfc
commit dd60adb0c6
2 changed files with 12 additions and 14 deletions

View File

@ -8,12 +8,23 @@ from typing import Dict, List, Type, Iterator, Iterable, Optional, ContextManage
from pathlib import Path
from contextlib import contextmanager, nullcontext
from ..compat import importlib_metadata, find_entry_points, get_dist_name
import niquests
from ..compat import importlib_metadata, find_entry_points, get_dist_name, urllib3
from ..utils import repr_dict, get_site_paths
from . import AuthPlugin, ConverterPlugin, FormatterPlugin, TransportPlugin
from .base import BasePlugin
# make sure all the plugins are forced to migrate to Niquests
# as it is a drop in replacement for Requests, everything should
# run smooth.
sys.modules["requests"] = niquests
sys.modules["requests.adapters"] = niquests.adapters
sys.modules["requests.sessions"] = niquests.sessions
sys.modules["requests.exceptions"] = niquests.exceptions
sys.modules["requests.packages.urllib3"] = urllib3
ENTRY_POINT_CLASSES = {
'httpie.plugins.auth.v1': AuthPlugin,

View File

@ -3,10 +3,6 @@ import socket
import pytest
from pytest_httpbin import certs
from pytest_httpbin.serve import Server as PyTestHttpBinServer
from sys import modules
import niquests
import urllib3
from .utils import ( # noqa
HTTPBIN_WITH_CHUNKED_SUPPORT_DOMAIN,
@ -28,15 +24,6 @@ from .utils.http_server import http_server, localhost_http_server # noqa
# Patch to support `url = str(server)` in addition to `url = server + '/foo'`.
PyTestHttpBinServer.__str__ = lambda self: self.url
# the mock utility 'response' only works with 'requests'
# we're trying to fool it, thinking requests is there.
# to remove when a similar (or same, but compatible)
# utility emerge for Niquests.
modules["requests"] = niquests
modules["requests.adapters"] = niquests.adapters
modules["requests.exceptions"] = niquests.exceptions
modules["requests.packages.urllib3"] = urllib3
@pytest.fixture(scope='function', autouse=True)
def httpbin_add_ca_bundle(monkeypatch):