pytest使用

pytest安装

环境介绍:macos 系统本身有python 2.7自己安装python3
命令行安装pytest:

pip3 install pytest

使用:
在有测试例的文件夹下直接运行pytest会自动运行以test开头或结尾的函数或者test类(不能有init函数),当然需要在相应python文件中import pytest,但是有可能会报以下错误:
command not found:pytest
解决方法:
使用python3 -m pytest进行执行,以下是一个测试案例:

#源程序 test_hello.py
import pytest
def hello():
	return "hello world"
def test_hello():
	assert hello()="hello world"

测试流程:

python3 -m pytest

-----------------------------------------------------------------------------------------
platform darwin -- Python 3.7.0, pytest-4.0.2, py-1.7.0, pluggy-0.8.0
rootdir: /Users/liukai/Desktop/py, inifile:
collected 1 item

test_hello.py .                                                                                                                                                            [100%]

======================== 1 passed in 0.03 seconds ===========================
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值