pytest 一个简单易用的测试框架

前言

最近帮测试同事在本地搭建一个测试框架pytest。于是总结了下安装使用步骤,记个笔记。

正文

放上快速上手的安装教程:

第一步:
pip3 install  pytest

第二步:
 pip3 install pytest-cov

第三步:
新建python脚本test_code.py 
代码如下:
import pytest
@pytest.fixture(scope='function')
def setup_function(request):
    def teardown_function():
        print("teardown_function called.")
    request.addfinalizer(teardown_function)  # 此内嵌函数做teardown工作
    print('setup_function called.')

@pytest.fixture(scope='module')
def setup_module(request):
    def teardown_module():
        print("teardown_module called.")
    request.addfinalizer(teardown_module)
    print('setup_module called.')

def test_1(setup_function):
    print('Test_1 called.')
def test_2():
    print("test_2")
然后运行命令行:
 pytest --cov-report=html --cov=./  test_code.py

按照前面这几步其实就可以用了。效果如下:
在这里插入图片描述

后记

由于我这边是短时间快速集成,所以总结的比较简单。pytest框架其实还有很多可以深究的地方,后面有机会可以多更几篇博文,深入探讨一下。(写到这我发现好像我埋了很多坑比如算法导论、排序算法、编程语言,,,,溜了溜了:)

附录

图片处理工具:http://xiuxiu.web.meitu.com/decorate/localfixes/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值