摘要: fake_useragent fake_useragent第三方库,来实现随机请求头的设置 安装 pip3 install fake-useragent 用法 from fake_useragent import UserAgent ua = UserAgent() print(ua.ie) pri 阅读全文
posted @ 2020-08-06 00:40 静心&得意 阅读(1497) 评论(0) 推荐(0) 编辑
摘要: requests+lxml爬取电子书 #!/usr/bin/python3 # -*- config:utf-8 -*- import os,sys from lxml import etree import requests import time import shutil from urlli 阅读全文
posted @ 2020-08-06 00:10 静心&得意 阅读(228) 评论(0) 推荐(0) 编辑
摘要: requests-post请求 基本用法 #! /usr/bin/python3 # -*- congfig:utf-8 -*- import requests def test_post(url): data = {'kw':"admin"} #请求体(字典) headers = {"user-a 阅读全文
posted @ 2020-08-05 23:37 静心&得意 阅读(273) 评论(0) 推荐(0) 编辑
摘要: requests-get请求 基本用法 #! /usr/bin/python3 # -*- congfig:utf-8 -*- import requests def test_get(url): r = requests.get(url) print(r.text) if __name__ == 阅读全文
posted @ 2020-08-05 23:36 静心&得意 阅读(211) 评论(0) 推荐(0) 编辑
摘要: requests入门 安装 pip install requests 发送请求的方法 import requests requests.post("http://httpbin.org/post") requests.put("http://httpbin.org/put") requests.de 阅读全文
posted @ 2020-08-05 23:34 静心&得意 阅读(156) 评论(0) 推荐(0) 编辑
摘要: pytest-配置文件 conftest.py 如果希望多个测试文件共享fixture,可以在公共目录下新建一个conftest.py文件,将fixture放在其中 例: 目录结构: . ├── conftest.py ├── __init__.py ├── test_001.py └── test 阅读全文
posted @ 2020-07-20 22:41 静心&得意 阅读(1013) 评论(0) 推荐(0) 编辑
摘要: pytest-fixture fixture是在测试函数运行前后,由pytest执行的外壳函数。fixture中的代码可以定制,满足多变的测试需求,包括定义传入测试中的数据集,配置测试前系统的初始状态,为批量测试提供数据源,等等。 #!/usr/bin/python3 #-*- conding:ut 阅读全文
posted @ 2020-07-20 22:40 静心&得意 阅读(584) 评论(0) 推荐(0) 编辑
摘要: 标记 pytest提供了标记机制,运行使用marker对测试用例做标记。一个测试用例可以有多个marker,一个marker也可以用来标记多个测试用例 自定义标记 test_003.py #!/usr/bin/python3 #-*- conding:utf-8 -*- import pytest 阅读全文
posted @ 2020-07-20 22:39 静心&得意 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 断言 pytest允许在assert关键字后面添加任何表达式(assert )。如果表达式的值通过bool转换后等于False,则意味着用例执行失败。 断言声明 #!/usr/bin/python3 #-*- conding:utf-8 -*- def test_one(): assert 1 == 阅读全文
posted @ 2020-07-20 22:37 静心&得意 阅读(257) 评论(0) 推荐(0) 编辑
摘要: 参数化 pytest使用parametrize标记实现参数化 @pytest.mark.parametrize(argnames,argvalues) parametrize()的第一个参数时用逗号分割的的字符串列表,第二个参数时一个值列表 #!/usr/bin/python3 #-*- condi 阅读全文
posted @ 2020-07-20 22:36 静心&得意 阅读(194) 评论(0) 推荐(0) 编辑