Skip to content

requests_mock plugin : No way of raising side_effect (requests.exceptions)  #5141

@jps-ob

Description

@jps-ob

I would like to test Connection/Timeout Exception for requests calls.

``
from unittest import mock

@mock.patch('requests.post', side_effect=requests.exceptions.ConnectTimeout)
def test_connection_error():
``

As stated in docs here

The fixture then provides the same interface as the requests_mock.Mocker letting you use requests-mock as you would expect.

requests-mock pytest plugin helps testing other failure scenarios, but not raising exception as side-effect. Hence I would like to define custom Adapter for requests-mock as documented here

This is not possible with requests-mock pytest plugin and without importing requests-mock module

However this would create namespace class hence, we need something like this
import requests_mock as req_mock_mod

Is there any possibility of using plugin to raise Request.Exception and/or define custom adapters ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions