getsentry / pytest-responses

py.test integration for responses

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Responses propagate to other tests unless responses.activate is used

bbc2 opened this issue · comments

import requests
import responses


def test_1():
    responses.add(responses.GET, 'http://example.net', json={'status': 'ok'})
    assert requests.get('http://example.net').json()['status'] == 'ok'


def test_2():
    responses.add(responses.GET, 'http://example.net', json={'status': 'fail'})
    assert requests.get('http://example.net').json()['status'] == 'fail'
========================================================= test session starts ==========================================================
platform linux -- Python 3.5.3rc1, pytest-3.0.5, py-1.4.32, pluggy-0.4.0
rootdir: /home/bertrand/test/pytest_responses_noreset, inifile: 
plugins: responses-0.1.0
collected 2 items 

test.py .F

=============================================================== FAILURES ===============================================================
________________________________________________________________ test_2 ________________________________________________________________

    @responses.activate
    def test_2():
        responses.add(responses.GET, 'http://example.net', json={'status': 'fail'})
>       assert requests.get('http://example.net').json()['status'] == 'fail'
E       assert 'ok' == 'fail'
E         - ok
E         + fail

test.py:13: AssertionError
================================================== 1 failed, 1 passed in 0.03 seconds ==================================================

Decorating the first test with responses.activate makes both tests pass.

+1 this is not how I expected the plugin to work. Tbh I thought there would be a pytest fixture called responses that I could use as responses.add etc. and that it would handle the resetting per test etc.