pytest的hello world

pyt1.py

def func(x):
print (x+1);
return x+1; def test_answer():
assert func(3) == 5; def test_2():
assert func(4) == 5;

使用py.test 测试

py.test pyt.py

输出

=============================== test session starts ===============================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2

collected 2 items

pyt1.py F.

==================================== FAILURES =====================================

___________________________________ test_answer ___________________________________

def test_answer():

>     assert func(3) == 5;

E     assert 4 == 5

E      +  where 4 = func(3)

pyt1.py:6: AssertionError

--------------------------------- Captured stdout ---------------------------------

4

======================= 1 failed, 1 passed in 0.03 seconds ========================

@@@@@@@@@@@@@@@@@@@@@@

另一种执行方法:

pyt2.py

import pytest

pytest.main("-x ./pyt1.py");

执行

python py2.py

输出:

=============================== test session starts ===============================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2

collected 2 items

pyt1.py F

==================================== FAILURES =====================================

___________________________________ test_answer ___________________________________

def test_answer():

>     assert func(3) == 5;

E     assert 4 == 5

E      +  where 4 = func(3)

pyt1.py:6: AssertionError

--------------------------------- Captured stdout ---------------------------------

4

!!!!!!!!!!!!!!!!!!!!! Interrupted: stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!

============================ 1 failed in 0.07 seconds =============================

pytest入门学习(2)的更多相关文章

  1. pytest入门学习(1)

    系统ubuntu 12.04 , 可上网 一.安装: 1.安装 setuptools 下载页面:https://bitbucket.org/pypa/setuptools/get/default.ta ...

  2. vue入门学习(基础篇)

    vue入门学习总结: vue的一个组件包括三部分:template.style.script. vue的数据在data中定义使用. 数据渲染指令:v-text.v-html.{{}}. 隐藏未编译的标 ...

  3. Hadoop入门学习笔记---part4

    紧接着<Hadoop入门学习笔记---part3>中的继续了解如何用java在程序中操作HDFS. 众所周知,对文件的操作无非是创建,查看,下载,删除.下面我们就开始应用java程序进行操 ...

  4. Hadoop入门学习笔记---part3

    2015年元旦,好好学习,天天向上.良好的开端是成功的一半,任何学习都不能中断,只有坚持才会出结果.继续学习Hadoop.冰冻三尺,非一日之寒! 经过Hadoop的伪分布集群环境的搭建,基本对Hado ...

  5. PyQt4入门学习笔记(三)

    # PyQt4入门学习笔记(三) PyQt4内的布局 布局方式是我们控制我们的GUI页面内各个控件的排放位置的.我们可以通过两种基本方式来控制: 1.绝对位置 2.layout类 绝对位置 这种方式要 ...

  6. PyQt4入门学习笔记(一)

    PyQt4入门学习笔记(一) 一直没有找到什么好的pyqt4的教程,偶然在google上搜到一篇不错的入门文档,翻译过来,留以后再复习. 原始链接如下: http://zetcode.com/gui/ ...

  7. Hadoop入门学习笔记---part2

    在<Hadoop入门学习笔记---part1>中感觉自己虽然总结的比较详细,但是始终感觉有点凌乱.不够系统化,不够简洁.经过自己的推敲和总结,现在在此处概括性的总结一下,认为在准备搭建ha ...

  8. Retrofit 入门学习

    Retrofit 入门学习官方RetrofitAPI 官方的一个例子 public interface GitHubService { @GET("users/{user}/repos&qu ...

  9. MyBatis入门学习教程-使用MyBatis对表执行CRUD操作

    上一篇MyBatis学习总结(一)--MyBatis快速入门中我们讲了如何使用Mybatis查询users表中的数据,算是对MyBatis有一个初步的入门了,今天讲解一下如何使用MyBatis对use ...

随机推荐

  1. poj 2888 Magic Bracelet <polya定理>

    题目:http://poj.org/problem?id=2888 题意:给定n(n <= 10^9)颗珠子,组成一串项链,每颗珠子可以用m种颜色中一种来涂色,如果两种涂色方法通过旋转项链可以得 ...

  2. Spring整合Struts2的方法

    一.基本支持 通常我们整合Spring和struts2的目的是让Spring来管理struts2的控制器.也就是说把Action交由Spring来管理,利用IOC的特性把Action注入到业务逻辑中. ...

  3. 6.5.1.3 Caching SHA-2 Pluggable Authentication

    MySQL :: MySQL 8.0 Reference Manual :: 6.5.1.3 Caching SHA-2 Pluggable Authentication https://dev.my ...

  4. C++正则表达式笔记之wregex

    遍历所有匹配 #include <iostream> #include <regex> using namespace std; int main() { wstring ws ...

  5. [Spring Batch 系列] 第一节 初识 Spring Batch

    距离开始使用 Spring Batch 有一段时间了,一直没有时间整理,现在项目即将完结,整理下这段时间学习和使用经历. 官网地址:http://projects.spring.io/spring-b ...

  6. SpringBoot-(5)-properties的使用

    项目中经常需要进行一些配置,一般会使用springboot默认的application.properties文件,也可以自己创建配置文件 一,application.properties配置 logg ...

  7. 【LeetCode】Insertion Sort List

    Sort a linked list using insertion sort. //用到O(N)的额外空间 public class Solution { public ListNode inser ...

  8. const与define应用上该怎么取舍

    const与define应用上该怎么取舍 #define WYB 100; const float WYB = 100; define是在预编译的时候展开替换的,const是编译运行阶段使用 defi ...

  9. 利用AutoLayout适配滚动视图和表视图

    1.新增一个contentView,设置为与滑动视图的父视图等高等宽. 2.利用代码 if(_MyTestTableView.frame.size.height != _MyTestTableView ...

  10. zookeeper+dubbo【转载】

    转载地址:http://ahua186186.iteye.com/blog/1912421 注:zookeeper集群是myid文件是没有后缀名的. 转自: http://www.verydemo.c ...