Why does the simplest requests_mock example fail with pytest?

左心房为你撑大大i 提交于 2019-12-04 13:03:31

Why it works in IPython seems like a mystery to me. To fix the issue just swap the lines of the function definition with the opening of the context manager.

# tests/test_mock.py

import requests
import requests_mock

def test_mock():
    with requests_mock.Mocker() as m:
        m.get('http://test.com', text='resp')
        assert requests.get('http://test.com').text == 'resp'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!