随笔分类 -  pytest

摘要:核心库 requests request请求 openpyxl excel文件操作 loggin 日志 smtplib 发送邮件 configparser unittest.mock mock服务 目录结构 base utils testDatas conf testCases testReport 阅读全文
posted @ 2020-09-26 22:10 子非鱼焉知鱼之乐丶 阅读(3338) 评论(4) 推荐(4)
摘要:背景 上篇博客介绍了allure集成在Jenkins,以及Jenkins构建本地job的方式. allure报告不会显示 @pytest.mark 标记的标记名称,这样不太方便阅读. 本篇博客介绍 allure 自带标记的方式,并可以将标记名称显示在报告中. allure标记的装饰器 BDD标记 @ 阅读全文
posted @ 2020-09-03 12:13 子非鱼焉知鱼之乐丶 阅读(280) 评论(0) 推荐(1)
摘要:前言 使用 allure 生成的报告,层次分明 我们借助上篇博客生成的报告,来认识下allure报告结构 Suites 结构 不同颜色方框代表不同状态 红色 failed 绿色 passed 黄色 error 灰色 skip 紫色 xfail 2. suite 结构分类: 模块名-函数用例\类函数用 阅读全文
posted @ 2020-08-29 16:44 子非鱼焉知鱼之乐丶 阅读(817) 评论(0) 推荐(1)
摘要:allure官方文档 https://docs.qameta.io/allure/ allure framework 官方介绍 Allure Framework是一种灵活的轻量级多语言测试报告工具,它不仅可以以简洁的网络报告形式非常简洁地显示已测试的内容,而且还允许参与开发过程的每个人从日常执行中提 阅读全文
posted @ 2020-08-29 12:57 子非鱼焉知鱼之乐丶 阅读(569) 评论(0) 推荐(1)
摘要:1、目的: 解决多个assert断言中,其中一个断言失败,后续断言不再继续执行的问题。 2、使用插件: pytest-assume 3、安装: pip install pytest-assume -i https://pypi.tuna.tsinghua.edu.cn/simple 4、assert 阅读全文
posted @ 2020-08-27 17:59 子非鱼焉知鱼之乐丶 阅读(349) 评论(0) 推荐(1)
摘要:插件:pytest-html github源码: https://github.com/pytest-dev/pytest-html 安装: pip install pytest-html -i https://pypi.tuna.tsinghua.edu.cn/simple 执行: 命令行执行: 阅读全文
posted @ 2020-08-27 10:28 子非鱼焉知鱼之乐丶 阅读(348) 评论(0) 推荐(1)
摘要:安装: pip install pytest-rerunfailures -i https://pypi.tuna.tsinghua.edu.cn/simple 环境要求: Python 3.5, 最高 3.8, or PyPy3 pytest 5.0或更高版本 参数: 命令行参数:--reruns 阅读全文
posted @ 2020-08-26 18:04 子非鱼焉知鱼之乐丶 阅读(320) 评论(0) 推荐(1)
摘要:1、pytest.ini的放置位置: 一般放在项目工程的根目录(即当前项目的顶级文件夹下),名字不能更改 2、pytest.ini的作用: 指定pytest的运行方式(命令行窗口输入pytest后,会读取pytest.ini中的配置信息,按配置的方式去运行) 3、cmd下使用 pytest -h 命 阅读全文
posted @ 2020-08-26 16:36 子非鱼焉知鱼之乐丶 阅读(499) 评论(0) 推荐(1)
摘要:当存在多套测试环境时,通过自定义命令行参数,快速切换host 查看pytest系统命令行参数:pytest -h 1、编辑 conftest.py: import os import pytest def pytest_addoption(parser): '''增加命令行参数 --cmdhost' 阅读全文
posted @ 2020-08-26 14:48 子非鱼焉知鱼之乐丶 阅读(779) 评论(0) 推荐(1)
摘要:设计思路:设计用例时,如果用例执行失败,则标记 xfail,所有引用该用例的其他用例,均调用该 xfail 标记 示例: # File : test_demo_16.py # IDE : PyCharm import pytest @pytest.fixture(params=[{'user': ' 阅读全文
posted @ 2020-08-26 09:05 子非鱼焉知鱼之乐丶 阅读(290) 评论(0) 推荐(1)
摘要:skip跳过用例: 跳过意味着你希望只在满足某些条件时测试才能通过,否则pytest应该跳过该测试。 常见的例子是跳过非windows平台上的仅windows测试,或者跳过依赖于当前不可用的外部资源(例如数据库)的测试。 # File : test_demo_15.py # IDE : PyChar 阅读全文
posted @ 2020-08-21 16:16 子非鱼焉知鱼之乐丶 阅读(228) 评论(0) 推荐(1)
摘要:pytest.raises() 函数文档如下: def raises( # noqa: F811 expected_exception: Union["Type[_E]", Tuple["Type[_E]", ...]], *args: Any, **kwargs: Any ) -> Union[" 阅读全文
posted @ 2020-08-21 14:11 子非鱼焉知鱼之乐丶 阅读(1747) 评论(0) 推荐(1)
摘要:在用例设计中,总会发生异常,甚至判断抛出的异常是否符合预期,可以使用两种异常断言的方式: 1)使用 try...except...else... 接收异常 2)使用 pytest.raises(typeException) 接收异常 # File : test_demo_12.py # IDE : 阅读全文
posted @ 2020-08-21 09:41 子非鱼焉知鱼之乐丶 阅读(932) 评论(0) 推荐(1)
摘要:断言: 将实际结果与预期结果进行比对。 pytest 使用 python 标准 assert 进行断言,assert 格式: assert expression [, arguments]# expression 为 True 则 pass# expression 为 False 则 抛出异常,有 阅读全文
posted @ 2020-08-21 09:26 子非鱼焉知鱼之乐丶 阅读(205) 评论(0) 推荐(1)
摘要:xfail 函数文档如下: def xfail(self,condition=None, reason=None, raises=None, run=True, strict=False): """mark the the test function as an expected failure i 阅读全文
posted @ 2020-08-20 10:24 子非鱼焉知鱼之乐丶 阅读(705) 评论(0) 推荐(1)
摘要:本篇博客比较下 parametrize 中 参数分别为 True 和 False 时的两种情况: 1) 当 indirect=False 时,argnames 参数被当成普通变量 import pytest@pytest.fixture(params=['a', 'b', 'c'])def fixt 阅读全文
posted @ 2020-08-20 08:58 子非鱼焉知鱼之乐丶 阅读(1067) 评论(0) 推荐(1)
摘要:问题:在验证 parametrize 源码的时候,发现传入 ids 中文 id 后,出现如下编码问题: # File : test_demo_10.py # IDE : PyCharm import pytest def division(a, b): return int(a / b) @pyte 阅读全文
posted @ 2020-08-19 17:52 子非鱼焉知鱼之乐丶 阅读(473) 评论(0) 推荐(1)
摘要:parametrize 允许在测试函数或类中定义多组参数和fixturesparametrize 函数文档如下: def parametrize(self,argnames, argvalues, indirect=False, ids=None, scope=None): """ Add new 阅读全文
posted @ 2020-08-19 17:40 子非鱼焉知鱼之乐丶 阅读(556) 评论(0) 推荐(1)
摘要:1、源码解释如下::arg autouse: if True, the fixture func is activated for all tests that can see it. If False (the default) then an explicit reference is need 阅读全文
posted @ 2020-08-19 13:54 子非鱼焉知鱼之乐丶 阅读(521) 评论(0) 推荐(1)
摘要:1、本文介绍,如何利用 fixture 的 params、ids 参数,实现前置条件参数化 使用 @pytest.fixture(param=[list1, list2, list3]) 的方式,以 request.param 的方式作为返回值供测试函数调用,param 中有多少元素,则调用几次,分 阅读全文
posted @ 2020-08-19 10:16 子非鱼焉知鱼之乐丶 阅读(736) 评论(2) 推荐(1)