随笔分类 - Python
摘要:pytest-xdist 分布式测试插件 安装 $ pip install pytest-xdist 测试代码准备 class Test: def test_sleep_2(self): sleep(2) assert False def test_sleep_3(self): sleep(3) a
阅读全文
摘要:记录一个 pytest-reruns 插件和 pytest-timeout 插件的 兼容性问题。 先说结论: 当两个插件一起使用时,需要设置 timeout_func_only=true 问题 接口自动化项目在容器内执行时 reruns 插件闪退,配置的 timeout 时间不生效,导致项目一直在阻
阅读全文
摘要:pytest-rerunfailures 插件,功能是用例执行失败可以重试。 python 3.6+ pytest 5.3+ 用例重试时,fixture 或 setup_class 也将被重新执行。 安装 $ pip install pytest-rerunfailures 使用 命令行使用 # 用
阅读全文
摘要:pytest-html 测试报告生成插件 安装 适用版本:Python >=3.6. $ pip install pytest-html 准备测试代码 # test_login.py class TestLogin: def test_success(self): print("login succ
阅读全文
摘要:通过 python 调用 $ python -m pytest [...] 等同于直接调用 pytest,通过 python 调用会将当前目录添加到 sys.path 退出码 Exit code 0: 找到所有测试用例并测试通过 Exit code 1: 部分用例运行失败 Exit code 2:
阅读全文
摘要:记录一个测试类变量初始化问题。 测试场景:初始化变量 a=1 ,每执行一条测试用例前,都使变量 a 自增 1,保证每条用例内的 a 都是不等的。 就像实例变量的值传递一样,如下: class Demo: def __init__(self): self.a = 1 print("init: ", s
阅读全文
摘要:使用 pytest 做自动化测试过程中,关于 allure 报告的使用方法汇总 python allure 包使用 allure 命令行工具 生成测试报告不启动服务 $ allure generate {allure_result} # -o 指定生成报告目录 # --clean 在生成新的 All
阅读全文
摘要:Translation:翻译插件,快捷键:cmd+ctl+u;https://yiiguxing.gitee.io/translation-plugin/start.html Markdown statistic: 统计代码行数 Json Parser:json 格式化插件 SonarLint:代码
阅读全文
摘要:插件介绍 PlantUML 是画程序时序图的,Pycharm 有插件,可以创建 *.puml 文件,非常方便。 官方网站:http://plantuml.com/sequence-diagram 在线使用:https://plantuml.ceshiren.com/uml/SyfFKj2rKt3Co
阅读全文
摘要:原因是配置了版本控制,但是目录却没有添加到版本控制内 设置 - VersionControl - Directory Mappings - 项目的 VCS 设置为 none 即可。
阅读全文
摘要:def _is_page(self, locator): """判断是否到达指定页面""" caller_name = traceback.extract_stack()[-2][2] is_page = self.ele_actions(locator).exists() self.log.opt
阅读全文
摘要:python 项目中的依赖库,可以创建一个requirements.txt文件来管理。 allure-pytest=2.12.0 pytest=7.2.0 pytest-rerunfailures=10.3 pytest-sugar=0.9.6 # 安装 $ pip install -r requi
阅读全文
摘要:Mac Python 3.7 https://www.modb.pro/db/454999 安装 # 搜索仓库 $ brew search gdb # 安装 $ brew install gdb Error: python@3.10: the bottle needs the Apple Comma
阅读全文
摘要:python 连接数据库操作 pymysql import pymysql def get_connect(): connect = pymysql.connect( host="xxx.com", port=3306, user="test", password="test1234", datab
阅读全文
摘要:数据处理 pandas 数据读取 pd.read_csv:csv/tsv/txt 用逗号、tab 分隔的纯文本文件 pd.read_excel::微软 xls 或者 xlsx 文件 pd.read_sql:mysql 关系型数据库 pd.read_csv 读取纯文本文件 userId,movieId
阅读全文
摘要:else 使用汇总。 问题 阅读别人代码,有点疑惑,精简后如下: def code_example(arg=None): for i in range(5): if arg: break else: print('else branch') 循环语句后面直接跟了 else 语句,未报错,程序正常运行
阅读全文
摘要:递归学习,通过汉诺塔游戏加强理解! 递归 在一个函数内部调用自身本身,就是递归函数。 阶乘 5 的阶乘为:5*4*3*2*1 n 的阶乘为:1*2*3*…*(n-1) 所以其实就是n*(n-1)的循环,只有当n=1时,需要特殊处理。 # 递归实现,暂不考虑负数和零 def fact(n): if n
阅读全文
摘要:# 安装包出现错误 $ pip install -r requirements.txt -i http://pypi.douban.com/simple/ ERROR: Could not find a version that satisfies the requirement pbr (from
阅读全文
摘要:python 3.7 Mac 安装 psycopg2 $ pip install psycopg2 ... Error: pg_config executable not found. ... 出现报错:Error: pg_config executable not found. 解决 参考:htt
阅读全文
摘要:说明文档:https://testerhome.com/topics/33229 本地 ws 服务 import asyncio import websockets # 接收客户端消息并处理,这里只是简单把客户端发来的返回回去 async def recv_user_msg(websocket):
阅读全文
