帮助模拟http调用并生成模拟代码
pytest-mock-helper的Python项目详细描述
#安装
``````
>pip install py test mock helper
````
>开发中需要这些环境:开发中需要这些环境:
``````
>导出pytest网络虚拟环境mock=develop
>导出pytest网络虚拟环境filepath=/tmp
``````
>例如,您有一个名为test-request.py的测试文件test.py:
```````````
>-*-编码:UTF-8-*-
detest_test_test_test_requests_send(capsys):
requests.get(https://httpbin.org)
``
与`--blockhtp `
``` ` `
` ` ` ` `
` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `=test session开始Python 3.64,Pyth3.3.2,PY1.1.2,PLUTCY-0.06
ROOTDIR:/用户/莱辛陶/程序/ PyTestNo网络模拟助手,iFIFLE:
插件:MOCK HelPer-0.0.2
收集1项
BR/>测试/TestSuffest.py.体育教育[100%]
======1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒=================1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒,===========
br/>===
===
==>复制下面的代码到模拟http的模拟http的下面的代码到模拟http的模拟http调用
定义模拟项(url,请求):
返回test_utils.fake_response(
rel_path=”/tmp/httpbin_org0“,
url=”https://httpbin.org/“,
status_code=200
)
````
同时下载的文件也会被保存到您的$py test_netowwork_netowwork文件路径:
`````
$ls/tmp/httpbin_org0
````
```````
``````````````````
/>```
py test tests/test_requests.py第二阶段:考试平台启动达尔文开始——Python 3.64,PYT3.3.2,PY-1.5.2,PLUCORY-0.06
插件:mock-helper-0.0.2
收集了1个项目
tests/test_requests.py f[100%]
=======================failures==============================================================
_________________________________________________________ test_requests_send _________________________________________________________
capsys = <_pytest.capture.CaptureFixture object at 0x10a3c3898>
def test_requests_send(capsys):
> requests.get("https://httpbin.org")
tests/test_requests.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:72: in get
return request('get', url, params=params,**kwargs)
/../../virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:58:in-request
return-session.request(method=method,url=url,**kwargs)
/../virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:508:in-request
resp=self.send(prep,**send_kwargs)
../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:618: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <StaseRealStutsDeReQuest[GET]=BR/> Krgs= {'Calt′:没有,“代理”:OrthDead():“false”,“超时”:没有,…} BR/>解析= PARSEREST(方案=“HTTPS”,NETROC=“HTTPBI.ORG”,PATH='/',PARAMS='',查询='',片段'''),NETLoC请求='httpbin.org'
路径='/'
def whitelisted(self,request,*args,**kwargs):
全局摘要
parsed=urlparse(request.url)
netloc=parsed.netloc
路径=parsed.path
如果白名单中的isinstance(netloc,str)和netloc:
返回self.old_send(request,*args,**kwargs)
如果不是,则开发:
日志程序。警告('拒绝到%s的http连接%netloc)
>;引发mockhttpcall(netloc)
e pytest_mock_helper.mockhttpcall:httpbin.org
----------------------------------捕获的stderr调用---------------------------------
pytest_mock_helper.py
```
``````
>pip install py test mock helper
````
>开发中需要这些环境:开发中需要这些环境:
``````
>导出pytest网络虚拟环境mock=develop
>导出pytest网络虚拟环境filepath=/tmp
``````
>例如,您有一个名为test-request.py的测试文件test.py:
```````````
>-*-编码:UTF-8-*-
detest_test_test_test_requests_send(capsys):
requests.get(https://httpbin.org)
``
与`--blockhtp `
``` ` `
` ` ` ` `
` ` ` ` `
` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` ` `=test session开始Python 3.64,Pyth3.3.2,PY1.1.2,PLUTCY-0.06
ROOTDIR:/用户/莱辛陶/程序/ PyTestNo网络模拟助手,iFIFLE:
插件:MOCK HelPer-0.0.2
收集1项
BR/>测试/TestSuffest.py.体育教育[100%]
======1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒=================1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒传递1.38秒,===========
br/>===
===
==>复制下面的代码到模拟http的模拟http的下面的代码到模拟http的模拟http调用
定义模拟项(url,请求):
返回test_utils.fake_response(
rel_path=”/tmp/httpbin_org0“,
url=”https://httpbin.org/“,
status_code=200
)
````
同时下载的文件也会被保存到您的$py test_netowwork_netowwork文件路径:
`````
$ls/tmp/httpbin_org0
```````
``````````````````
/>```
py test tests/test_requests.py第二阶段:考试平台启动达尔文开始——Python 3.64,PYT3.3.2,PY-1.5.2,PLUCORY-0.06
插件:mock-helper-0.0.2
收集了1个项目
tests/test_requests.py f[100%]
=======================failures==============================================================
_________________________________________________________ test_requests_send _________________________________________________________
capsys = <_pytest.capture.CaptureFixture object at 0x10a3c3898>
def test_requests_send(capsys):
> requests.get("https://httpbin.org")
tests/test_requests.py:7:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:72: in get
return request('get', url, params=params,**kwargs)
/../../virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/api.py:58:in-request
return-session.request(method=method,url=url,**kwargs)
/../virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:508:in-request
resp=self.send(prep,**send_kwargs)
../../.virtualenvs/pytest-plugin/lib/python3.6/site-packages/requests/sessions.py:618: in send
r = adapter.send(request, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <StaseRealStutsDeReQuest[GET]=BR/> Krgs= {'Calt′:没有,“代理”:OrthDead():“false”,“超时”:没有,…} BR/>解析= PARSEREST(方案=“HTTPS”,NETROC=“HTTPBI.ORG”,PATH='/',PARAMS='',查询='',片段'''),NETLoC请求='httpbin.org'
路径='/'
def whitelisted(self,request,*args,**kwargs):
全局摘要
parsed=urlparse(request.url)
netloc=parsed.netloc
路径=parsed.path
如果白名单中的isinstance(netloc,str)和netloc:
返回self.old_send(request,*args,**kwargs)
如果不是,则开发:
日志程序。警告('拒绝到%s的http连接%netloc)
>;引发mockhttpcall(netloc)
e pytest_mock_helper.mockhttpcall:httpbin.org
pytest_mock_helper.py
```