当前位置: 首页 > news >正文

pytest笔记: pytest单元测试框架

第一步:安装 和查看版本

pycharm settings 查看 

 第二步: 编写test_example.py

def  inc(x):return  x+1
def test_answer():assert inc(4) ==5

第三步:在当前路径下执行pytest 命令

PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example>      pytest
======================================================================== test session starts ========================================================================
platform win32 -- Python 3.10.9, pytest-7.1.2, pluggy-1.0.0
rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example
plugins: anyio-3.5.0
collected 1 item                                                                                                                                                     test_sample.py .                                                                                                                                               [100%]========================================================================= 1 passed in 0.07s =========================================================================
PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example>      pytest --version
pytest 7.1.2
PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example>

test_sample.py  后面带了个“.” 表示通过

def inc(x):return x + 1def test_answer():ret = inc(3)assert ret == 111

如果不符合预期显示结果如下

PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example> pytest
======================================================================== test session starts ========================================================================
platform win32 -- Python 3.10.9, pytest-7.1.2, pluggy-1.0.0
rootdir: E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example
plugins: anyio-3.5.0
collected 1 item                                                                                                                                                     test_sample.py F                                                                                                                                               [100%]============================================================================= FAILURES ==============================================================================
____________________________________________________________________________ test_answer ____________________________________________________________________________def test_answer():ret = inc(3)
>       assert ret == 1111
E       assert 4 == 1111test_sample.py:7: AssertionError
====================================================================== short test summary info ======================================================================
FAILED test_sample.py::test_answer - assert 4 == 1111
========================================================================= 1 failed in 0.40s =========================================================================
PS E:\data\web测试\Selenium3自动化测试实战——基于Python语言\mycode\pytest_example>

http://www.lryc.cn/news/144738.html

相关文章:

  • vulnhub Seattle-0.0.3
  • MYSQL 添加行号将行号写入到主键的列
  • 前端命令npm 、 cnpm、 pnpm、yarn 、 npx、nvm的区别
  • Linux 发行版 Debian 宣布支持龙芯 LoongArch 架构
  • PConv : Run, Don’t Walk: Chasing Higher FLOPS for Faster Neural Networks
  • Python中怎么解决内存管理的问题? - 易智编译EaseEditing
  • 【JavaEE】Spring事务-事务的基本介绍-事务的实现-@Transactional基本介绍和使用
  • CentOs下面安装jenkins记录
  • 海康威视相机-LINUX SDK 开发
  • AI助力智能安检,基于图像目标检测实现危险品X光智能安全检测系统
  • 开源软件的崛起:历史与未来
  • apk 静默安装
  • Unity记录4.2-存储-从json文件获取Tile路径
  • vue3页面传参?
  • NB水表和LoRa水表有哪些不同之处?
  • Java进阶(6)——抢购问题中的数据不安全(非原子性问题) Java中的synchronize和ReentrantLock锁使用 死锁及其产生的条件
  • SpringBoot初级开发--加入Log4j进行日志管理打印(6)
  • 计算机竞赛 基于GRU的 电影评论情感分析 - python 深度学习 情感分类
  • android logcat问题 怎么换成旧版
  • 监听的用法watch
  • XML—标记语言
  • 图数据库Neo4j学习五渲染图数据库neo4jd3
  • AI增强的社交网络·导师·电话客服……
  • c# Task异步使用
  • QuickLook概述和使用以及常用插件
  • 1A快恢复整流二极管型号汇总
  • 【element-ui】el-dialog改变宽度
  • 第三讲,实践编程 Eigen
  • POI实现百万数据导出
  • 如何制作党建专题汇报片