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

Pytest 的小例子

一个简单的例子

下面代码保存到test_pytest.py

一个简单的例子
def inc(x):return x + 1def test_answer():assert inc(3) == 5def test_ask():assert inc(4) == 5

pytest 需要安装一下 

pip install pytest
(Venv) D:\pythonwork>pip install pytest
Collecting pytestDownloading pytest-7.4.3-py3-none-any.whl (325 kB)|█████████████                   | 133 kB 100 kB/s eta 0:00:02|██████████████                  | 143 kB 100 kB/s eta 0:00:0|███████████████                 | 153 kB 100 kB/s eta 0:00:|████████████████                | 163 kB 100 kB/s eta 0:00|█████████████████               | 174 kB 100 kB/s eta 0:0|██████████████████              | 184 kB 100 kB/s eta 0:|███████████████████             | 194 kB 100 kB/s eta 0|████████████████████            | 204 kB 100 kB/s eta|█████████████████████           | 215 kB 100 kB/s eta|██████████████████████          | 225 kB 100 kB/s et|███████████████████████         | 235 kB 100 kB/s e|████████████████████████        | 245 kB 100 kB/s|█████████████████████████       | 256 kB 100 kB/s|██████████████████████████      | 266 kB 100 kB/|███████████████████████████     | 276 kB 100 kB|████████████████████████████    | 286 kB 100 k|█████████████████████████████   | 296 kB 100|██████████████████████████████  | 307 kB 100|███████████████████████████████ | 317 kB 10|████████████████████████████████| 325 kB 1
00 kB/s
Collecting tomli>=1.0.0; python_version < "3.11"Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting colorama; sys_platform == "win32"Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Collecting pluggy<2.0,>=0.12Downloading pluggy-1.3.0-py3-none-any.whl (18 kB)
Collecting exceptiongroup>=1.0.0rc8; python_version < "3.11"Downloading exceptiongroup-1.2.0-py3-none-any.whl (16 kB)
Collecting packagingDownloading packaging-23.2-py3-none-any.whl (53 kB)|██████████████████▌             | 30 kB 495 kB/s eta 0:|█████████████████████████       | 40 kB 114 kB/s|███████████████████████████████ | 51 kB 136|████████████████████████████████| 53 kB 11
1 kB/s
Collecting iniconfigDownloading iniconfig-2.0.0-py3-none-any.whl (5.9 kB)
Installing collected packages: tomli, colorama, pluggy, exceptiongroup, packagin
g, iniconfig, pytest
Successfully installed colorama-0.4.6 exceptiongroup-1.2.0 iniconfig-2.0.0 packa
ging-23.2 pluggy-1.3.0 pytest-7.4.3 tomli-2.0.1
WARNING: You are using pip version 20.2.3; however, version 23.3.1 is available.

pytest运行

F.  说明已经False失败和. true 一个通过和一个失败。

(Venv) D:\pythonwork>pytest
============================= test session starts =============================
platform win32 -- Python 3.8.7, pytest-7.4.3, pluggy-1.3.0
rootdir: D:\pythonwork
collected 2 itemstest_python.py F.                                                        [100%]================================== FAILURES ===================================
_________________________________ test_answer _________________________________def test_answer():
>       assert inc(3) == 5
E       assert 4 == 5
E        +  where 4 = inc(3)test_python.py:6: AssertionError
=========================== short test summary info ===========================
FAILED test_python.py::test_answer - assert 4 == 5
========================= 1 failed, 1 passed in 0.15s =========================

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

相关文章:

  • 大数据(十一):概率统计基础
  • web前端之TypeScript
  • 计网Lesson6 - IP 地址分类管理
  • Nat. Mach. Intell. | 预测人工智能的未来:在指数级增长的知识网络中使用基于机器学习的链接预测
  • MySQL海量数据配置优化教程
  • Mac-idea快捷键操作
  • HarmonyOS脚手架:UI组件之文本和图片
  • 详细学习Pyqt5中的6种按钮
  • 【工具】Zotero|使用Zotero向Word中插入引用文献(2023年)
  • 利用Python爬虫爬取豆瓣电影排名信息
  • 灯光开不了了,是不是NVIDIA的问题
  • 线性可分SVM摘记
  • LabVIEW在调用image.cpp或drawmgr.cpp因为DAbort而崩溃
  • nodejs微信小程序+python+PHP贵州旅游系统的设计与实现-计算机毕业设计推荐MySQL
  • WebUI自动化学习(Selenium+Python+Pytest框架)003
  • python+Appium自动化:python多线程多并发启动appium服务
  • 【计算机网络笔记】802.11无线局域网
  • 用C++和python混合编写数据采集程序?
  • Android HCI日志分析案例1
  • LangChain(0.0.339)官方文档四:Prompts下——prompt templates的存储、加载、组合和部分格式化
  • 鸿蒙开发笔记
  • 「计算机网络」Cisco Packet Tracker计算机网络仿真器的使用
  • 【已解决】if lock.acquire(block, timeout):KeyboardInterrupt
  • 将Excel中的数据导入shell脚本,并调用expect脚本
  • elementui el-table用span-method方法对相同的列名或行名进行合并
  • 汇编语言实现音乐播放器
  • 大型网站系统架构演化(Web)
  • 三轴加速度计LIS2DW12开发(2)----基于中断信号获取加速度数据
  • Shell循环:whileuntil
  • Redis 安装部署