Created
October 19, 2017 03:10
-
-
Save jamielennox/d996d818eb98c5f38a8e0eb3b7376bd7 to your computer and use it in GitHub Desktop.
requests_mock and pytest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import thing | |
import pytest | |
import requests_mock as rm_module | |
@pytest.fixture | |
def requests_mock(request): | |
m = rm_module.Mocker() | |
m.start() | |
request.addfinalizer(m.stop) | |
return m | |
def test_a_thing(requests_mock): | |
requests_mock.get('https://httpbin.org/get', json={'fake': 'thing'}) | |
json = thing.do_thing() | |
assert json == {'fake': 'thing'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def do_thing(): | |
return requests.get('https://httpbin.org/get').json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment