-
Notifications
You must be signed in to change notification settings - Fork 48
Closed
Description
Hi,
I'm in the process of converting my requests-based application to httpx, and therefore also having to convert all the responses-based mocks within my tests. I wanted to avoid coupling to another client-specific test library like RESPX and instead use mocket.
However, I get an error when trying to instantiate httpx's AsyncClient. Here's a simple async pytest:
import json
import httpx
from mocket import async_mocketize
from mocket.mockhttp import Entry
@async_mocketize
async def test_mocket():
async with httpx.AsyncClient() as client:
url = "https://example.org/"
data = {"message": "Hello"}
Entry.single_register(
Entry.GET,
url,
body=json.dumps(data),
headers={'content-type': 'application/json'}
)
response = await client.get(url)
assert response.json() == dataStacktrack
tests/adapters/junifer/client/test_mocket.py:7 (test_mocket)
@async_mocketize
async def test_mocket():
> async with httpx.AsyncClient() as client:
test_mocket.py:10:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_client.py:1394: in __init__
self._transport = self._init_transport(
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_client.py:1442: in _init_transport
return AsyncHTTPTransport(
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_transports/default.py:261: in __init__
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_config.py:49: in create_ssl_context
return SSLConfig(
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_config.py:73: in __init__
self.ssl_context = self.load_ssl_context()
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_config.py:85: in load_ssl_context
return self.load_ssl_context_verify()
/Users/gregorybrown/Library/Caches/pypoetry/virtualenvs/tariff-management-6yv2RoDp-py3.10/lib/python3.10/site-packages/httpx/_config.py:122: in load_ssl_context_verify
context = self._create_default_ssl_context()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <httpx._config.SSLConfig object at 0x10c1cb8e0>
def _create_default_ssl_context(self) -> ssl.SSLContext:
"""
Creates the default SSLContext object that's used for both verified
and unverified connections.
"""
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
set_minimum_tls_version_1_2(context)
context.options |= ssl.OP_NO_COMPRESSION
> context.set_ciphers(DEFAULT_CIPHERS)
E TypeError: 'NoneType' object is not callable
Is httpx not supported? There are no references to it in the source or docs.
Thanks!
Metadata
Metadata
Assignees
Labels
No labels