pytest框架学习

     最近参加了一个培训班,我学习的格外用心,也许是这几年参加工作以来比较有激情的一次。当然是我这几年来太放松自己了,自从踏入测试这个行业以来,做的一直是功能测试,技术方面没有积累,没有提升,是时候静下心来沉淀下自己啦!

     这次上课的老师来自思科,最主要的是她和我一样是个妈妈,比我估计也就大个两三岁,但是显然的,她的成就是我的好几倍!我是比较喜欢她的,希望自己有朝一日也能和她一样。

      pytest的有关学习,对于一只菜鸟,把过程记录下来。

     1. 安装pytest

       a首先安装好python---

      b. pip 安装Pytest----在cmd下运行:pip install pytest

          注意必须先把C:Python27Scripts(python的安装路径在c盘)放到环境变量下

       c.pytest --version 

    b步骤也可以使用源码安装,需要自己下载pytest-3.0.6.tar.gz,运行:python setup.py install

    2.第一个实例

# content of test_sample.py
def func(x):
    return x + 1
def test_answer():
    assert func(3) == 5
# py.test
=========================================================================================================== test session starts ===========================================================================================================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
collected 1 items 

test_sample.py F

================================================================================================================ FAILURES =================================================================================================================
_______________________________________________________________________________________________________________ test_answer _______________________________________________________________________________________________________________

    def test_answer():
>       assert func(3) == 5
E       assert 4 == 5
E        +  where 4 = func(3)

test_sample.py:8: AssertionError
====================================================================================

pytest通过标准测试发现规则发现test_answer函数,通常是查找 test_前缀。我们得到了一个故障报告,因为我们调用func(3)没有返回5。

原文地址:https://www.cnblogs.com/feiyi211/p/6625771.html