帮助模拟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
```



欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java未从Facebook OAuth接收名字、姓氏和姓氏   我自己代码中的java ConcurrentModificationException   java在Android上获得单像素TIFF图像   java图形输出中的swing集成弹出窗口“通知”   将数据库表中的所有数据集插入jTable Java   java如何使用Hibernate获取不完整的集合?   打印无法从java连接到打印机   java使用分隔符拆分带引号的字符串   java Axis2禁用严格验证(wsdl2java中的Eosv)允许什么,如何使其更加严格?   java有人能帮我处理循环代码吗   java将JsonObject数组转换为整数   JavaXWiki扩展:检测事件空间创建   java如何设置图表的文本方向以使用poi旋转所有文本?   eche RecyclerView项的java Set自定义字体   java单元测试带有私有构造函数的spring组件,无需注入   用户界面如何在java中动态显示一组多个元素?   如何从java应用程序调用IDL(交互式数据语言)?   Java的内置库实现