10 2020 档案

摘要:a =dict(one=1,two=2,three=3) b = {'one':1,'two':2,'three':3} c = dict(zip(['one','two','three'],[1,2,3])) d = dict([('one', 1), ('two', 2), ('three', 阅读全文
posted @ 2020-10-29 09:27 沧海1024 阅读(489) 评论(0) 推荐(1)
摘要:bisect模块提供的功能: 一共包含四个函数 insort_right(a, x, lo=0, hi=None) bisect_right(a, x, lo=0, hi=None) insort_left(a, x, lo=0, hi=None) bisect_left(a, x, lo=0, h 阅读全文
posted @ 2020-10-28 10:02 沧海1024 阅读(193) 评论(0) 推荐(0)
摘要:有时候我们需要初始化一个嵌套着几个列表的列表,这种情况下推荐使用列表推导式 代码1: def test01(): l = [["_"] * 3 for i in range(3)] print(l) l[1][2] = "x" print(l) if __name__ == '__main__': 阅读全文
posted @ 2020-10-26 21:16 沧海1024 阅读(184) 评论(0) 推荐(0)
摘要:概况: 1、多个接口测试用例单线程执行很慢,需要用pytest-xdist插件提高执行速度; 2、存在session级别fixture,只能执行一次:执行登录等前置操作,获取token等全局数据,如果多次执行,则之前的token会失效 3、pytest-xdist插件没有实现session只执行一次 阅读全文
posted @ 2020-10-26 10:49 沧海1024 阅读(1709) 评论(1) 推荐(1)
摘要: 阅读全文
posted @ 2020-10-24 20:37 沧海1024 阅读(76) 评论(0) 推荐(0)
摘要:import collections from random import choice Card = collections.namedtuple('Card',['rank','suit']) class FrenchDeck: ranks = [str(n) for n in range(2, 阅读全文
posted @ 2020-10-23 09:31 沧海1024 阅读(324) 评论(0) 推荐(0)
摘要:1、指定范围的浮点数:random.uniform(1, 100) 2、指定小数位数进行四舍五入:random.uniform(1, 100), 7 3、string中的随机字符串: 4、由指定集合中的元素生成指定位数不重复的列表:random.sample(string.hexdigits, +4 阅读全文
posted @ 2020-10-20 15:40 沧海1024 阅读(322) 评论(0) 推荐(0)
摘要:方式一:在线引用 前提:网络可以访问外网 在html文件的head中加入以下代码即可 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integ 阅读全文
posted @ 2020-10-17 16:43 沧海1024 阅读(1273) 评论(0) 推荐(0)
摘要:测试代码如下 from timeit import Timer def fun1(): a = [] for i in range(10000): li = [i] a = a + li def fun2(): a = [i for i in range(10000)] def fun3(): a 阅读全文
posted @ 2020-10-13 10:28 沧海1024 阅读(202) 评论(0) 推荐(0)
摘要:一、前置条件 Linux服务器默认安装的是python2的环境; 不能将python2环境卸载了再装python3环境,这样可能会导致很多莫名其妙的问题,应该保持多个python环境 二、安装步骤 1、安装相关的依赖包 yum -y install zlib-devel bzip2-devel op 阅读全文
posted @ 2020-10-12 12:39 沧海1024 阅读(314) 评论(0) 推荐(0)
摘要:一、环境准备: 1、安装allure 2、安装allure-pytest:pip install allure-pytest 二、allure基本参数说明 三、实践代码 #conftest.py import pytest @pytest.fixture(scope="session") def l 阅读全文
posted @ 2020-10-10 11:06 沧海1024 阅读(1089) 评论(0) 推荐(0)
摘要:#conftest.py import os import pytest def pytest_addoption(parser): """利用钩子函数添加命令行参数""" parser.addoption( "--envhost", # action="append", #如果是append,则d 阅读全文
posted @ 2020-10-09 22:39 沧海1024 阅读(661) 评论(0) 推荐(1)
摘要:1、自定义一个带参数的fixture 用request接收参数,固定写法,换成其他的会报错 如果是字典形式,按照字典取值方式获取参数值 import pytest @pytest.fixture(scope="module") def log_fixture(request): print("前置条 阅读全文
posted @ 2020-10-09 16:25 沧海1024 阅读(434) 评论(0) 推荐(0)
摘要:import pymysql db_conf = { "host": "xxxxxxx", "port": 3306, "user": "root", "passwd": "123456", "charset": "utf8", # "utf-8"会报错 } class DbConnect(): d 阅读全文
posted @ 2020-10-09 09:51 沧海1024 阅读(485) 评论(0) 推荐(0)
摘要:1、requests请求放回的response对象有三种格式 content:字节输出byte text:字符串输出 json:json格式的数据,转为字典格式输出 2、dict与json关系 dict转json:json.dumps(dict) 3、eval函数,将参数当做python语法来执行, 阅读全文
posted @ 2020-10-07 15:30 沧海1024 阅读(237) 评论(0) 推荐(0)
摘要:在做接口、UI自动化的时候,我们可以用yaml文件来管理测试用例的步骤、数据,因为每次测试的数据需要动态变换,所以yaml文件中相关参数可能需要用变量表示。那么,我们怎么进行变量的传值呢? 这里可以用到字符串的模板替换功能,官方文档:https://docs.python.org/zh-cn/3/l 阅读全文
posted @ 2020-10-04 15:52 沧海1024 阅读(2028) 评论(0) 推荐(1)
摘要:当我们在生成数据的时候,常用到%d方式进行格式化生成数据。 比如要生成11位的手机号,可以这样: def test_create_data(): data = ['138%08d' %x for x in range(20)] print(data) 当填充内容不足8位的时候,用0进行填充输出内容: 阅读全文
posted @ 2020-10-03 10:34 沧海1024 阅读(642) 评论(0) 推荐(0)