# requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.example.com', port=443): Max retries exceeded with url: /v1/items (Caused by NewConnectionError(...))

- **ID:** `python/pytest-requests-mock-adapter-not-active`
- **Domain:** python
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

requests_mock.Mocker was used as a context manager but the client under test creates its own Session (or uses requests.Session() directly), which is not the session the adapter was mounted on.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.11.x | active | — | — |
| 1.12.x | active | — | — |

## Workarounds

1. **** (94% success)
   ```
   import requests, requests_mock

def test_fetch():
    session = requests.Session()
    with requests_mock.Mocker(session=session) as m:
        m.get('https://api.example.com/v1/items', json=[])
        client = MyClient(session=session)
        assert client.fetch_items() == []
   ```
2. **** (92% success)
   ```
   @pytest.fixture
def mocked_session():
    s = requests.Session()
    with requests_mock.Mocker(session=s) as m:
        yield s, m

def test_x(mocked_session):
    s, m = mocked_session
    m.get('https://api.example.com/v1/items', json=[])
    assert MyClient(session=s).fetch_items() == []
   ```

## Dead Ends

- **** — Module-level mocker still only patches the default session; code that instantiates its own Session bypasses it. (85% fail)
- **** — Falls back to the real network, which is exactly what CI cannot access; the ConnectionError persists. (90% fail)
