随笔分类 - Python
摘要:1、运行方式 2、断言 3、Fixture 4、参数化 5、运行测试 6、跳过测试 7、生成测试报告 8、pytest插件 1、运行方式 1. 命令行模式 命令行中执行 pytest -s login.py 2. 主函数模式 if __name__ == '__main__': pytest.mai
阅读全文
摘要:1、用 yagmail 发送邮件 通过 pip 命令安装 pip install yagmail 示例: import yagmail yag = yagmail.SMTP(user='发送方邮箱',password='授权码', host='smtp.qq.com') # 邮件正文 content
阅读全文
摘要:1、时间操作的方法 time.time():获取当前时间戳。 time.ctime():当前时间的字符串形式。 time.localtime():当前时间的 struct_time 形式。 time.strftime():用来获取当前时间,可以将时间格式化为字符串。 import time t1 =
阅读全文
摘要:Python 内置了 requests 模块,该模块主要用来发送 HTTP 请求,每次调用 requests 请求之后,会返回一个 response 对象,该对象包含了具体的响应信息。 本文内容如下: 一、使用requests库发送不同类型的请求 二、使用requests库传递URL参数、设置请求头
阅读全文
摘要:一、文件操作步骤 1. 打开文件 2. 读、写文件 读: 将文件内容读入内存 写: 将内容写入文件 3. 关闭文件 二、操作文件的函数/方法 open 函数:打开文件,并且返回文件对象 read 方法:将文件内容读取到内存 write 方法:将指定内容写入文件 close 方法:关闭文件 读取文件
阅读全文
摘要:记录一下在测试登录接口时如何实现参数化。 1、基于json文件实现参数化 # 构造测试数据 def build_data(): # 指定文件路径 json_file = "json文件路径" # 打开json文件 test_data = [] with open(json_file, encodin
阅读全文
摘要:一、要素 TestCase:测试用例 TestSuite:测试套件(多条测试用例集合在一起) TestRunner:执行测试用例和测试套件 TestLoader:用来加载 TestCase 到 TestSuite 中,即加载满足条件的测试用例,并把测试用例封装成测试套件。 Fixture:对一个测试
阅读全文
摘要:1、异常捕获完整语法 try: 可能出现异常的代码 except 错误类型 1: 出现异常的处理代码 except (错误类型 2,错误类型 2): 出现异常的处理代码 except Exception as result: 出现未知异常的处理代码 else: 没有异常执行的代码 finally:
阅读全文
摘要:1、操作流程 # 导包 import pymysql # 创建连接 conn = pymysql.connect(host="localhost", # 主机名或IP地址 port=3306, # 端口 user="root", # 用户名 password="root", # 密码 databas
阅读全文

浙公网安备 33010602011771号