摘要: 前言: # 函数参数中存在两种特殊的参数,动态参数 *args、关键字参数 **kwargs。 # 在一个函数里面只能有一个动态参数、关键字参数,可以同时存在形参、默认参数、动态参数、关键字参数 # 动态参数 *args、关键字参数 **kwargs 常用做不定长的输入。 动态参数示例代码: # 动 阅读全文
posted @ 2020-08-27 21:32 子非鱼焉知鱼之乐丶 阅读(291) 评论(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 子非鱼焉知鱼之乐丶 阅读(314) 评论(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 子非鱼焉知鱼之乐丶 阅读(315) 评论(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 子非鱼焉知鱼之乐丶 阅读(271) 评论(0) 推荐(1) 编辑
摘要: 1、pytest.ini的放置位置: 一般放在项目工程的根目录(即当前项目的顶级文件夹下),名字不能更改 2、pytest.ini的作用: 指定pytest的运行方式(命令行窗口输入pytest后,会读取pytest.ini中的配置信息,按配置的方式去运行) 3、cmd下使用 pytest -h 命 阅读全文
posted @ 2020-08-26 16:36 子非鱼焉知鱼之乐丶 阅读(428) 评论(0) 推荐(1) 编辑
摘要: 当存在多套测试环境时,通过自定义命令行参数,快速切换host 查看pytest系统命令行参数:pytest -h 1、编辑 conftest.py: import os import pytest def pytest_addoption(parser): '''增加命令行参数 --cmdhost' 阅读全文
posted @ 2020-08-26 14:48 子非鱼焉知鱼之乐丶 阅读(739) 评论(0) 推荐(1) 编辑
摘要: 设计思路:设计用例时,如果用例执行失败,则标记 xfail,所有引用该用例的其他用例,均调用该 xfail 标记 示例: # File : test_demo_16.py # IDE : PyCharm import pytest @pytest.fixture(params=[{'user': ' 阅读全文
posted @ 2020-08-26 09:05 子非鱼焉知鱼之乐丶 阅读(267) 评论(0) 推荐(1) 编辑
摘要: skip跳过用例: 跳过意味着你希望只在满足某些条件时测试才能通过,否则pytest应该跳过该测试。 常见的例子是跳过非windows平台上的仅windows测试,或者跳过依赖于当前不可用的外部资源(例如数据库)的测试。 # File : test_demo_15.py # IDE : PyChar 阅读全文
posted @ 2020-08-21 16:16 子非鱼焉知鱼之乐丶 阅读(203) 评论(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 子非鱼焉知鱼之乐丶 阅读(1584) 评论(0) 推荐(1) 编辑
摘要: 在用例设计中,总会发生异常,甚至判断抛出的异常是否符合预期,可以使用两种异常断言的方式: 1)使用 try...except...else... 接收异常 2)使用 pytest.raises(typeException) 接收异常 # File : test_demo_12.py # IDE : 阅读全文
posted @ 2020-08-21 09:41 子非鱼焉知鱼之乐丶 阅读(798) 评论(0) 推荐(1) 编辑