pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高。根据pytest的官方网站介绍,它具有如下特点:
-
非常容易上手,入门简单,文档丰富,文档中有很多实例可以参考 能够支持简单的单元测试和复杂的功能测试 支持参数化
执行测试过程中可 -
以将某些测试跳过(skip),或者对某些预期失败的case标记成失败 支持重复执行(rerun)失败的case
-
支持运行由nose, unittest编写的测试case 可生成html报告 方便的和持续集成工具jenkins集成 可支持执行部分用例
-
具有很多第三方插件,并且可以自定义扩展
查看pip
-
打开cmd,运行:echo %path% 查看路径
-
运行:pip。无法识别这个命令,原因是环境变量中没有添加pip的安装路径。
-
添加pip的环境变量。在Windows cmd中运行:set path=%path%;C:\Python27\Scripts
-
运行:echo %path% 。
-
运行:pip。pip可以正常运行。
安装pytest
命令行输入:pip install -U pytest,显示证书有问题,证书版本过期了。
Could not fetch URL https://pypi.org/simple/pytest/: There was a problem confirming the ssl certificate:
HTTPSConnectionPool(host=‘pypi.org’, port=443): Max retries exceeded
with url: /simple/pytest/ (Caused by
SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED]
certificate verify failed: self signed certificate in certificate
chain (_ssl.c:1108)’))) - skipping ERROR: Could not find a version
that satisfies the requirement pytest (from versions: none) ERROR: No
matching distribution found for pytest
出现这个错误的原因是python.org已经不支持TLSv1.0和TLSv1.1了。更新pip可以解决这个问题。
下载pytest
pip install pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
然后就可以了
查看pytest是否安装成功
pip show pytest
查看pytest版本
pytest --version
到此pytest就安装完毕了。