py.响应的测试集成
pytest-responses的Python项目详细描述
在py.test-powered测试套件中自动激活响应(从而防止http请求)。
$ pip install pytest-responses
如果特定测试需要访问外部域,可以使用withoutresponses标记:
@pytest.mark.withoutresponsesdeftest_disabled():withpytest.raises(ConnectionError):requests.get('http://responses.invalid')assertlen(responses.calls)==0
此外,您还可以使用响应设备:
deftest_enabled(responses):withpytest.raises(ConnectionError):requests.get('http://responses.invalid')assertlen(responses.calls)==1