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 + 1 def test_answer():
assert inc(3) == 5 def test_wcf():
assert inc(3) > 5 def 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 items test_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文件都进行测试。

pytest学习(1)的更多相关文章

  1. [转载]pytest学习笔记

    pytest学习笔记(三)   接着上一篇的内容,这里主要讲下参数化,pytest很好的支持了测试函数中变量的参数化 一.pytest的参数化 1.通过命令行来实现参数化 文档中给了一个简单的例子, ...

  2. Pytest学习(三) - setup和teardown的使用

    一.前言 从文章标题可以看出,就是初始化和释放的操作,根据我的java习惯来学习pytest,个人感觉没差太多,理解上也不是很难. 哦,对了,差点跑题了,这个框架是基于Python语言的,在学习的时候 ...

  3. pytest学习笔记

    From: https://blog.csdn.net/gaowg11/article/details/54910974 由于对测试框架了解比较少,所以最近看了下pytest测试框架,对学习心得做个记 ...

  4. pytest 学习笔记一 入门篇

    前言 之前做自动化测试的时候,用的测试框架为Python自带的unittest框架,随着工作的深入,发现了另外一个框架就是pytest (官方地址文档http://www.pytest.org/en/ ...

  5. pytest学习笔记(一)

    这两天在学习pytest,之前有小用到pytest,觉得这个测试框架很灵巧,用在实现接口自动化(pytest+requests)非常的轻便,然后很有兴致的决定学习下,然后又发现了pytest-sele ...

  6. Pytest学习(一)- 入门及基础

    前言 十一也赶上自己刚出院,本想在十一放假前用假期刷完Pytest的,结果被希洛克神话吸引,再次回归毒奶粉,一直奋斗到距离上班还有两天,引导石刷没了,就没了智慧. 当然也没出过神话,结果一怒之下卸载, ...

  7. Pytest学习(二) - 断言的使用

    一.前言 学习pytest总会习惯性的和unittest对比使用,自然就断言pytest和unittest也是有些区别的. 二.断言对比 unittest 断言 assertEqual(a, b) # ...

  8. Pytest学习笔记3-fixture

    前言 个人认为,fixture是pytest最精髓的地方,也是学习pytest必会的知识点. fixture用途 用于执行测试前后的初始化操作,比如打开浏览器.准备测试数据.清除之前的测试数据等等 用 ...

  9. pytest学习笔记(三)

    接着上一篇的内容,这里主要讲下参数化,pytest很好的支持了测试函数中变量的参数化 一.pytest的参数化 1.通过命令行来实现参数化 文档中给了一个简单的例子, test_compute.py ...

  10. pytest学习笔记(二)

    继续文档的第二章 (一)pytest中可以在命令行中静态/动态添加option,这里没什么好讲的,略过... 这里面主要讲下如何试用skip/xfail,还有incremental(包含一些列的测试步 ...

随机推荐

  1. lintcode-133-最长单词

    133-最长单词 给一个词典,找出其中所有最长的单词. 样例 在词典 { "dog", "google", "facebook", &quo ...

  2. JavaScript五种继承方式详解

    本文抄袭仅供学习http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_inheritance.html 一. 构造函数绑定 ...

  3. WebService使用介绍(二)

    Soap soap是什么 SOAP 是一种网络通信协议 SOAP即Simple Object Access Protocol简易对象访问协议 SOAP 用于跨平台应用程序之间的通信 SOAP 被设计用 ...

  4. [洛谷P1536]村村通

    题意:多组数据,当n为0时结束,每组数据表示有n个村子,m条路,求还需要建多少条路,使得所有的村子联通题解:用并查集求出有多少个联通块,然后求解 C++ Code: #include<cstdi ...

  5. 2018牛客多校第一场 D.Two Graphs

    题意: n个点,m1条边的图E1,n个点,m2条边的图E2.求图E2有多少子图跟图E1同构. 题解: 用STL的全排列函数next_permutation()枚举映射.对于每一种映射枚举每一条边判断合 ...

  6. [Leetcode] Merge two sorted lists 合并两已排序的链表

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  7. 【HDU 4300 Clairewd’s message】

    Clairewd is a member of FBI. After several years concealing in BUPT, she intercepted some important ...

  8. 【BZOJ 3376】[Usaco2004 Open]Cube Stacking 方块游戏 带权并查集

    这道题一开始以为是平衡树结果发现复杂度过不去,然后发现我们一直合并而且只是记录到最低的距离,那么就是带权并查集了,带权并查集的权一般是到根的距离,因为不算根要好打,不过还有一些其他的,具体的具体打. ...

  9. border-1px;避免移动端下边框部分2px

    .border-1px { position: relative; } .border-1px:after { display: block; position: absolute; left:; b ...

  10. Jquery Ajax异步上传

    <script> $(function(){ $('#filephoto').change(function(imgFile){ console.log(imgFile) var file ...