Skip to content

Instantly share code, notes, and snippets.

@mykwillis
Forked from jamielennox/test_thing.py
Last active April 4, 2018 10:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mykwillis/3785c8f92e600abf9a33b46568206b10 to your computer and use it in GitHub Desktop.
Save mykwillis/3785c8f92e600abf9a33b46568206b10 to your computer and use it in GitHub Desktop.
requests_mock and pytest
import thing
import pytest
import requests_mock as rm_module
@pytest.fixture
def requests_mock(request):
with rm_module.Mocker() as m:
yield 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'}
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