getsentry / responses

A utility for mocking out the Python Requests library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to pass through real request by default? It will raise requests.exceptions.ConnectionError

vba34520 opened this issue · comments

commented

main.py

from flask import Flask

app = Flask(__name__)


@app.route('/')
def index():
    return 'Hello World!'


@app.route('/user/<name>')
def user(name):
    return f'Hello {name}!'


if __name__ == '__main__':
    app.run()

test_main.py

import requests
import responses


def test_api():
    with responses.RequestsMock(assert_all_requests_are_fired=False) as rsps:
        rsps.get(url='http://127.0.0.1:5000/', body='test')
        resp = requests.get('http://127.0.0.1:5000/')
        assert resp.text == 'test'  # mock interface
        resp = requests.get('http://127.0.0.1:5000/user/responses')
        assert resp.text == 'Hello responses!'  # real interface

It raised requests.exceptions.ConnectionError: Connection refused by Responses - the call doesn't match any registered mock.

How to fix it? Thanks!

Hello,
Did you already go through the steps described in the readme?

commented

No, I did not.

Is it possible to go through automatially?

Because there are many interfaces from different origin servers to call.

Yes, please go through readme and let us know