pytest入门

  • 安装pytest
  • 运行pytest
  • pytest常用命令

1. 安装pytest

pip install pytest

2. 运行pytest

2.1 pytest默认搜索当前目录下以test_, _test结尾的测试函数(默认是以test开头,结尾,但是这个是可以自己配置的,后面再说)

pytest/ch1/test_one.py

def test_1():
assert (1, 2, 3) == (1, 2, 3) def test_2():
assert 1 == 2

运行指令
$cd /pytest/ch1
$pytest

2.2 运行单个测试函数

$ cd /pytest/ch1
$ pytest test_one.py

2.3 运行单个测试用例

$ cd /pytest/ch1
$ pytest test_one.py
$ pytest test_one.py::test_1

3. 常用的命令

3.1  -v 查看执行结果的详细信息

3.2 -q 简化输出

3.3 -l  显示错误堆栈里的局部变量

3.4 -m 标记测试分组,用@pytest.mark.xxx装饰器做标记

pytest/ch1/test_two.py

import pytest

@pytest.mark.smoke
def test_pass():
assert (1, 2, 3) == (1, 2, 3) def test_fail():
assert 1 == 2

$ cd /pytest/ch1
$ pytest -m smoke test_two.py

观察结果,只运行了标记为smoke的测试用例

最新文章

  1. linux下redis的安装与部署及基础命令
  2. jQuery学习-css、class操作、动画方法的运用、jQ操作Dom节点
  3. java.lang.NoClassDefFoundError: com/google/gson/Gson错误的解决
  4. 转载:移动前端开发之viewport的深入理解
  5. Careercup - Facebook面试题 - 6204973461274624
  6. SecureCRT自动断开连接的问题
  7. python 下载安装及setuptools应用
  8. time返回当前的 Unix 时间戳而$_SERVER["REQUEST_TIME"]得到请求开始时的时间戳
  9. 【Lucene4.8教程之六】QueryParser与Query子类:如何生成Query对象
  10. python开发的一些tips
  11. 键盘enter事件时间页面绑定
  12. C++友元
  13. 文件断点续传原理与实现—— ESFramework 通信框架4.0 进阶(12)
  14. [转]整理jquery使用好习惯
  15. Lintcode399 Nuts & Bolts Problem solution 题解
  16. Ninja编译过程分析
  17. MongoDB AUTH结果验证
  18. visual studio 2017 installer 安装包制作过程出现的问题---无法注册模块 HRESULT -2147024769 请与您的技术支持人员联系
  19. Yum安装Zabbix4.2.0
  20. 2017-2018-2 20155234『网络对抗技术』Exp5:MSF基础应用

热门文章

  1. Kitty基于Spring Boot、Spring Cloud、Vue.js、Element实现前后端分离的权限管理系统
  2. 前后端分离Java后端主流开发环境框架20200622
  3. 群晖DS218+部署kafka
  4. 2.3 spring5源码系列---内置的后置处理器PostProcess加载源码
  5. Error: pg_config executable not found.
  6. Redis中的一致性哈希问题
  7. CentOS7下一键小白搭建seafile pro云盘
  8. 【有奖众测】给HMS Core文档提建议,赢大奖华为Watch!
  9. tp3.2 前端截取字符串
  10. java enum 枚举值