VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > python入门教程 >
  • pytest快速入门1-安装和开始

pytest是python中较常用的测试框架,官方文档见:

https://docs.pytest.org/en/stable/contents.html#toc

 

安装命令:

pip install -U pytest

检查是否安装成功命令:

pytest --version

能查到版本号说明安装OK,否则嘿嘿。

创建第一个测试脚本test_sample.py:

复制代码
# content of test_sample.py
def func(x):
    return x + 1


def test_answer():
    assert func(3) == 5
复制代码

通过命令pytest执行,得到结果如下:

$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-6.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item

test_sample.py F                                                     [100%]

================================= FAILURES =================================
_______________________________ test_answer ________________________________

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

test_sample.py:6: AssertionError
========================= short test summary info ==========================
FAILED test_sample.py::test_answer - assert 4 == 5
============================ 1 failed in 0.12s =============================

跟Junit测试框架类似都有assert的方法来对比实际结果和预期的结果是否一致,如果不一致则返回F,并指出错误的位置。
 

出处:https://www.cnblogs.com/vigogogogo/p/13943375.html


相关教程