pytest学习(1)
pytest是python的一个测试框架,主要是用来进行一些小的测试。
在pycharm中,缺省用的是unittest,这里说明如何设置为pytest。
当然,第一部是安装pytest
pip3 install pytest
然后,在pycharm中,files-》settings-》tools=》python integrated tools=》设定default test runner
然后,写一个简单的py程序(记住,test_*.py or *_test.py):
def inc(x):return x + 1def test_answer():assert inc(3) == 5def test_wcf():assert inc(3) > 5def test_hy():assert inc(3) < 5
运行后:
C:\Python35\python.exe C:\Users\wcf\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\171.4694.67\helpers\pycharm\_jb_pytest_runner.py --path C:/fitme/work/nltk/test_5.py
Testing started at 18:53 ...
Launching py.test with arguments C:/fitme/work/nltk/test_5.py in C:\fitme\work\nltk
============================= test session starts =============================
platform win32 -- Python 3.5.3, pytest-3.1.3, py-1.4.34, pluggy-0.4.0
rootdir: C:\fitme\work\nltk, inifile:
collected 3 itemstest_5.py F
test_5.py:3 (test_answer)
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)test_5.py:5: AssertionError
F
test_5.py:6 (test_wcf)
def test_wcf():
> assert inc(3) > 5
E assert 4 > 5
E + where 4 = inc(3)test_5.py:8: AssertionError
.================================== FAILURES ===================================
_________________________________ test_answer _________________________________def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)test_5.py:5: AssertionError
__________________________________ test_wcf ___________________________________def test_wcf():
> assert inc(3) > 5
E assert 4 > 5
E + where 4 = inc(3)test_5.py:8: AssertionError
===================== 2 failed, 1 passed in 0.05 seconds ======================Process finished with exit code 0
如果只运行pytest,则对当前目录下所有的test_*.py or *_test.py文件都进行测试。
转载于:https://www.cnblogs.com/aomi/p/7213907.html
pytest学习(1)相关推荐
- Pytest学习-如何在用例代码中调用fixtrue时传入参数
前言 在使用Pytest的时候,为了提高代码的复用性,我们一般会把一些常用操作,比如把登录方法写在 conftest.py 中,然后在不同测试用例中,调用这个登录方法. 但是在测试用例中,我们可能需要 ...
- pytest学习和使用8-fixture如何实现teardown功能?(yield的使用)
8-fixture如何实现teardown功能?(yield的使用) 1引入 2 yield说明 3 yield的使用 3.1 实现teardown 3.2 yield返回值 4 yield+with ...
- Pytest学习笔记4——测试步骤
引言 大家都知道功能测试用例组成的基本要素:用例ID,模块名,测试用例名称,前置条件,测试步骤,预期结果,实际结果等等.前置条件以及测试参数化,前面已经讲过,现在简单讲一下pytest测试步骤的用法. ...
- pytest学习和使用12-Unittest和Pytest参数化详解
12-Unittest和Pytest参数化详解 1 Unittest参数化 1.1 ddt 1.1.1 简介 1.1.2 说明 1.1.3 安装 1.1.4 版本信息 1.1.5 实例1 1.1.6 ...
- pytest学习笔记
目录 1.虚拟环境准备 2.安装pytest 3.pytest使用约束 4.执行方式 5.pytest常用运行参数介绍 6.解决大批量执行测试case问题多进程 7.失败重跑机制(以下两种均可) 8. ...
- pytest学习(2)
可以把多个test放在一个class里, class TestClass(object):def test_one(self):x = "this"assert 'h' in xd ...
- pytest学习:setup、teardown、setup_class、teardown_class的区别
记录pytest 与 unittest内的前后置函数操作区别 pytest示例 setup_class:单个测试类开始前执行1次 setup:每个测试函数执行前执行1次 teardown:每个测试函数 ...
- Pytest学习笔记(4)-Fixture装置
文章目录 Fixture装置 前言 fixture用途 fixture优势 fixture语法 fixture定义 fixture调用 fixture作为函数的入参调用 使用 @pytest.mark ...
- pytest学习和使用22-allure特性 丨总览中的Environment、Categories设置以及Flaky test使用
22-allure特性 丨总览中的Environment和Categories设置 1 Environment设置 1.1 设置方法 1.2 创建文件 2 Categories设置 2.1 设置方式 ...
- Pytest学习笔记(3)-Setup和Teardown
文章目录 setup和teardown 前言 module(模块)级别 function(函数)级别 class(类)级别 method(方法)级别 混合使用 总结 setup和teardown 前言 ...
最新文章
- uva 707(记忆化搜索)
- dropbox文件_Dropbox即将发布的扩展程序更新将添加更多文件编辑支持,包括Pixlr照片...
- 前端学习(1906)vue之电商管理系统电商系统之渲染修改用户的表单
- C# 实现酒店房态图
- 2016年ICT行业前瞻:竞合生态,牵着手 一起走
- 关于EmmyLua插件创建Lua脚本Require失败的问题
- Hadoop原理及架构
- 挑战程序竞赛系列(22):3.2弹性碰撞
- java持久化 seri_Java 的序列化 (Serialization) 教程
- MacOS上符号执行模块angr和z3-solver模块的安装
- scrapy数据存入mysql_Scrapy爬虫实例教程(二)---数据存入MySQL
- maya建模与骨骼动画快速实现人工鱼
- Net-MVC+EasyUI之 TinyMCE使用
- ChatGPT会砸了谷歌的饭碗吗?(附彩蛋)
- Win10系统内置杀毒软件Windows Defender卸载方法
- VMware虚拟机拷贝mac冲突解决方法(及软件安装)
- partition 0 ended too near . couldnt find ntldr
- Python实现替换照片人物背景,精细到头发丝(附上代码) | 机器学习
- CHIL-SQL-DEFAULT 约束
- TE、TM、TEM模式的区别
热门文章
- apollo-配置管理中心-安装
- 【Windows C++笔记】winbase.h
- [Python3] 面向对象编程
- 计蒜客模拟赛D2T3 蒜头君救人:用bfs转移状压dp
- 算法系列:量子计算与量子通信
- Out of resources when opening file './xxx.MYD' (Errcode: 24)
- c# 保存数据到txt (追加)
- SGU[222] Little Rooks
- NetScaler Active-Active模式
- bootstrap-内联文本元素-斜体