Skip to content

tests/test_http.py::TrueHttpEntryTestCase::test_truesendall fails with hostname issue on Darwin ARM #287

@nemith

Description

@nemith

When running the test suite on my ARM based macbook it is failing on main with the following error:

❯ make safetest
SKIP_TRUE_REDIS=1 SKIP_TRUE_HTTP=1 .venv/bin/pytest
/Users/bbennett/bcroot/tmp/python-mocket/.venv/lib/python3.12/site-packages/pytest_asyncio/plugin.py:217: PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
The event loop scope for asynchronous fixtures will default to the fixture caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to function scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

  warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
========================================================================= test session starts =========================================================================
platform darwin -- Python 3.12.10, pytest-8.3.5, pluggy-1.5.0 -- /Users/bbennett/bcroot/tmp/python-mocket/.venv/bin/python3
cachedir: .pytest_cache
rootdir: /Users/bbennett/bcroot/tmp/python-mocket
configfile: pyproject.toml
testpaths: tests, mocket
plugins: anyio-4.9.0, pook-2.1.3, asyncio-0.26.0, cov-6.1.1
asyncio: mode=Mode.STRICT, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 170 items

tests/test_asyncio.py::test_asyncio_record_replay PASSED                                                                                                        [  0%]
tests/test_asyncio.py::test_aiohttp PASSED                                                                                                                      [  1%]
tests/test_compat.py::test_unknown_binary PASSED                                                                                                                [  1%]
tests/test_http.py::TrueHttpEntryTestCase::test_truesendall SKIPPED (condition: os.getenv("SKIP_TRUE_HTTP", False))                                             [  2%]
tests/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_chunk_recording SKIPPED (condition: os.getenv("SKIP_TRUE_HTTP", False))                        [  2%]
tests/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_gzip_recording SKIPPED (condition: os.getenv("SKIP_TRUE_HTTP", False))                         [  3%]
tests/test_http.py::TrueHttpEntryTestCase::test_truesendall_with_recording SKIPPED (condition: os.getenv("SKIP_TRUE_HTTP", False))                              [  4%]
tests/test_http.py::TrueHttpEntryTestCase::test_wrongpath_truesendall SKIPPED (condition: os.getenv("SKIP_TRUE_HTTP", False))                                   [  4%]
tests/test_http.py::HttpEntryTestCase::test_does_not_fail_because_all_entries_are_served PASSED                                                                 [  5%]
tests/test_http.py::HttpEntryTestCase::test_fail_because_entry_not_served PASSED                                                                                [  5%]
tests/test_http.py::HttpEntryTestCase::test_file_object PASSED                                                                                                  [  6%]
tests/test_http.py::HttpEntryTestCase::test_mockhttp_entry_collect_duplicates PASSED                                                                            [  7%]
tests/test_http.py::HttpEntryTestCase::test_multi_register PASSED                                                                                               [  7%]
tests/test_http.py::HttpEntryTestCase::test_multipart PASSED                                                                                                    [  8%]
tests/test_http.py::HttpEntryTestCase::test_post_file_object PASSED                                                                                             [  8%]
tests/test_http.py::HttpEntryTestCase::test_raise_exception_from_register PASSED                                                                                [  9%]
tests/test_http.py::HttpEntryTestCase::test_raise_exception_from_single_register PASSED                                                                         [ 10%]
tests/test_http.py::HttpEntryTestCase::test_register PASSED                                                                                                     [ 10%]
tests/test_http.py::HttpEntryTestCase::test_request_bodies PASSED                                                                                               [ 11%]
tests/test_http.py::HttpEntryTestCase::test_same_url_different_methods PASSED                                                                                   [ 11%]
tests/test_http.py::HttpEntryTestCase::test_sendall PASSED                                                                                                      [ 12%]
tests/test_http.py::HttpEntryTestCase::test_sendall_double PASSED                                                                                               [ 12%]
tests/test_http.py::HttpEntryTestCase::test_sendall_json PASSED                                                                                                 [ 13%]
tests/test_http.py::HttpEntryTestCase::test_sockets PASSED                                                                                                      [ 14%]
tests/test_http.py::HttpEntryTestCase::test_suggestion_for_register_and_body PASSED                                                                             [ 14%]
tests/test_http.py::HttpEntryTestCase::test_suggestion_for_register_and_status PASSED                                                                           [ 15%]
tests/test_http.py::HttpEntryTestCase::test_truesendall_with_dump_from_recording PASSED                                                                         [ 15%]
tests/test_http_gevent.py::HttpEntryTestCase::test_does_not_fail_because_all_entries_are_served PASSED                                                          [ 16%]
tests/test_http_gevent.py::HttpEntryTestCase::test_fail_because_entry_not_served PASSED                                                                         [ 17%]
tests/test_http_gevent.py::HttpEntryTestCase::test_file_object PASSED                                                                                           [ 17%]
tests/test_http_gevent.py::HttpEntryTestCase::test_mockhttp_entry_collect_duplicates PASSED                                                                     [ 18%]
tests/test_http_gevent.py::HttpEntryTestCase::test_multi_register PASSED                                                                                        [ 18%]
tests/test_http_gevent.py::HttpEntryTestCase::test_multipart PASSED                                                                                             [ 19%]
tests/test_http_gevent.py::HttpEntryTestCase::test_post_file_object PASSED                                                                                      [ 20%]
tests/test_http_gevent.py::HttpEntryTestCase::test_raise_exception_from_register PASSED                                                                         [ 20%]
tests/test_http_gevent.py::HttpEntryTestCase::test_raise_exception_from_single_register PASSED                                                                  [ 21%]
tests/test_http_gevent.py::HttpEntryTestCase::test_register PASSED                                                                                              [ 21%]
tests/test_http_gevent.py::HttpEntryTestCase::test_request_bodies PASSED                                                                                        [ 22%]
tests/test_http_gevent.py::HttpEntryTestCase::test_same_url_different_methods PASSED                                                                            [ 22%]
tests/test_http_gevent.py::HttpEntryTestCase::test_sendall PASSED                                                                                               [ 23%]
tests/test_http_gevent.py::HttpEntryTestCase::test_sendall_double PASSED                                                                                        [ 24%]
tests/test_http_gevent.py::HttpEntryTestCase::test_sendall_json PASSED                                                                                          [ 24%]
tests/test_http_gevent.py::HttpEntryTestCase::test_sockets PASSED                                                                                               [ 25%]
tests/test_http_gevent.py::HttpEntryTestCase::test_suggestion_for_register_and_body PASSED                                                                      [ 25%]
tests/test_http_gevent.py::HttpEntryTestCase::test_suggestion_for_register_and_status PASSED                                                                    [ 26%]
tests/test_http_gevent.py::HttpEntryTestCase::test_truesendall_with_dump_from_recording PASSED                                                                  [ 27%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_does_not_fail_because_all_entries_are_served PASSED                                                    [ 27%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_fail_because_entry_not_served PASSED                                                                   [ 28%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_file_object PASSED                                                                                     [ 28%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_mockhttp_entry_collect_duplicates PASSED                                                               [ 29%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_multi_register PASSED                                                                                  [ 30%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_multipart PASSED                                                                                       [ 30%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_post_file_object PASSED                                                                                [ 31%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_raise_exception_from_register PASSED                                                                   [ 31%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_raise_exception_from_single_register PASSED                                                            [ 32%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_register PASSED                                                                                        [ 32%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_request_bodies PASSED                                                                                  [ 33%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_same_url_different_methods PASSED                                                                      [ 34%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_sendall PASSED                                                                                         [ 34%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_sendall_double PASSED                                                                                  [ 35%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_sendall_json PASSED                                                                                    [ 35%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_sockets PASSED                                                                                         [ 36%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_suggestion_for_register_and_body PASSED                                                                [ 37%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_suggestion_for_register_and_status PASSED                                                              [ 37%]
tests/test_http_gevent.py::GeventHttpEntryTestCase::test_truesendall_with_dump_from_recording PASSED                                                            [ 38%]
tests/test_http_httpx.py::HttpxEntryTestCase::test_httprettish_httpx_session FAILED                                                                             [ 38%]

============================================================================== FAILURES ===============================================================================
__________________________________________________________ HttpxEntryTestCase.test_httprettish_httpx_session __________________________________________________________

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
>           yield

.venv/lib/python3.12/site-packages/httpx/_transports/default.py:101:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.12/site-packages/httpx/_transports/default.py:394: in handle_async_request
    resp = await self._pool.handle_async_request(req)
.venv/lib/python3.12/site-packages/httpcore/_async/connection_pool.py:256: in handle_async_request
    raise exc from None
.venv/lib/python3.12/site-packages/httpcore/_async/connection_pool.py:236: in handle_async_request
    response = await connection.handle_async_request(
.venv/lib/python3.12/site-packages/httpcore/_async/connection.py:101: in handle_async_request
    raise exc
.venv/lib/python3.12/site-packages/httpcore/_async/connection.py:78: in handle_async_request
    stream = await self._connect(request)
.venv/lib/python3.12/site-packages/httpcore/_async/connection.py:124: in _connect
    stream = await self._network_backend.connect_tcp(**kwargs)
.venv/lib/python3.12/site-packages/httpcore/_backends/auto.py:31: in connect_tcp
    return await self._backend.connect_tcp(
.venv/lib/python3.12/site-packages/httpcore/_backends/anyio.py:113: in connect_tcp
    with map_exceptions(exc_map):
../../../.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py:158: in __exit__
    self.gen.throw(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

map = {<class 'TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>, <class 'anyio.BrokenResourceError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: ExceptionMapping) -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from exc
E                   httpcore.ConnectTimeout

.venv/lib/python3.12/site-packages/httpcore/_exceptions.py:14: ConnectTimeout

The above exception was the direct cause of the following exception:

self = <tests.test_http_httpx.HttpxEntryTestCase testMethod=test_httprettish_httpx_session>

    @async_httprettified
    async def test_httprettish_httpx_session(self):
        expected_response = {"origin": "127.0.0.1"}

        HTTPretty.register_uri(
            HTTPretty.GET,
            self.target_url,
            body=json.dumps(expected_response),
        )

        async with httpx.AsyncClient() as client:
>           response = await client.get(self.target_url)

tests/test_http_httpx.py:23:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.12/site-packages/httpx/_client.py:1768: in get
    return await self.request(
.venv/lib/python3.12/site-packages/httpx/_client.py:1540: in request
    return await self.send(request, auth=auth, follow_redirects=follow_redirects)
.venv/lib/python3.12/site-packages/httpx/_client.py:1629: in send
    response = await self._send_handling_auth(
.venv/lib/python3.12/site-packages/httpx/_client.py:1657: in _send_handling_auth
    response = await self._send_handling_redirects(
.venv/lib/python3.12/site-packages/httpx/_client.py:1694: in _send_handling_redirects
    response = await self._send_single_request(request)
.venv/lib/python3.12/site-packages/httpx/_client.py:1730: in _send_single_request
    response = await transport.handle_async_request(request)
.venv/lib/python3.12/site-packages/httpx/_transports/default.py:393: in handle_async_request
    with map_httpcore_exceptions():
../../../.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/contextlib.py:158: in __exit__
    self.gen.throw(value)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        global HTTPCORE_EXC_MAP
        if len(HTTPCORE_EXC_MAP) == 0:
            HTTPCORE_EXC_MAP = _load_httpcore_exceptions()
        try:
            yield
        except Exception as exc:
            mapped_exc = None

            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc

            if mapped_exc is None:  # pragma: no cover
                raise

            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ConnectTimeout

.venv/lib/python3.12/site-packages/httpx/_transports/default.py:118: ConnectTimeout
-------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------
WARNING  asyncio:base_events.py:1994 Executing <Task pending name='anyio._core._sockets.connect_tcp.<locals>.try_connect' coro=<connect_tcp.<locals>.try_connect() running at /Users/bbennett/bcroot/tmp/python-mocket/.venv/lib/python3.12/site-packages/anyio/_core/_sockets.py:175> wait_for=<Future pending cb=[Task.task_wakeup()] created at /Users/bbennett/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/asyncio/base_events.py:448> cb=[TaskGroup._spawn.<locals>.task_done() at /Users/bbennett/bcroot/tmp/python-mocket/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:794] created at /Users/bbennett/.local/share/uv/python/cpython-3.12.10-macos-aarch64-none/lib/python3.12/asyncio/tasks.py:420> took 5.007 seconds
=========================================================================== tests coverage ============================================================================
__________________________________________________________ coverage: platform darwin, python 3.12.10-final-0 __________________________________________________________

Name                                   Stmts   Miss  Cover   Missing
--------------------------------------------------------------------
mocket/__init__.py                        14      0   100%
mocket/compat.py                          24      2    92%   26-27
mocket/decorators/__init__.py              0      0   100%
mocket/decorators/async_mocket.py          7      0   100%
mocket/decorators/mocketizer.py           46      3    93%   20, 22, 57
mocket/entry.py                           41      6    85%   11, 24, 32-34, 42
mocket/exceptions.py                       4      0   100%
mocket/inject.py                          32      2    94%   70, 80
mocket/io.py                              12      0   100%
mocket/mocket.py                          90      6    93%   16-17, 34, 41, 122, 128
mocket/mocks/__init__.py                   0      0   100%
mocket/mocks/mockhttp.py                 141      3    98%   50-51, 235
mocket/mocks/mockredis.py                 53     21    60%   14, 19, 25-26, 32-48, 56, 69-72, 75, 79-83, 87, 91
mocket/mode.py                            22      7    68%   28-31, 35-42
mocket/plugins/__init__.py                 0      0   100%
mocket/plugins/aiohttp_connector.py        8      0   100%
mocket/plugins/httpretty/__init__.py      67      9    87%   17, 21, 77, 81-84, 89, 106, 108
mocket/plugins/pook_mock_engine.py        48     24    50%   3-4, 15-19, 32-39, 45-60, 67-68, 72
mocket/recording.py                       89      5    94%   19, 111, 121, 142-143
mocket/socket.py                         164     17    90%   48, 52, 61-63, 96, 104, 149, 158, 196, 211-218, 222
mocket/ssl/__init__.py                     0      0   100%
mocket/ssl/context.py                     39      4    90%   36, 58, 77-78
mocket/ssl/socket.py                      53     14    74%   57, 74-95
mocket/types.py                           11      0   100%
mocket/urllib3.py                         10      3    70%   11, 19-20
mocket/utils.py                           20      1    95%   37
--------------------------------------------------------------------
TOTAL                                    995    127    87%
Coverage XML written to file coverage.xml
======================================================================= short test summary info =======================================================================
FAILED tests/test_http_httpx.py::HttpxEntryTestCase::test_httprettish_httpx_session - httpx.ConnectTimeout
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
=============================================================== 1 failed, 60 passed, 5 skipped in 6.69s ===============================================================
make: *** [Makefile:41: safetest] Error 1

Found while trying to update nix packages (reported here :NixOS/nixpkgs#400373)

EDITED: Had the wrong test error included the correct one

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions