unittest 到pytest的转换

一直都在使用unittest,突然发现有朋友在用pytest,研究之后发现,我去,这也太好用了吧,为啥没让我早些发现!!

现在把经历写下来,希望对大家有帮助

写在前面:pytest完全兼容unittest的代码,如果你也准备转换到pytest,之前旧的代码不需要修改,依然可以正常运行

安装:
pip install pytest

运行
在文件的最前面引入pytest
import pytest

pytest.main()运行测试用例

还可以传递参数的方式运行: pytest.main(["-v", “-s”]))
设置默认的测试工具
unittest 到pytest的转换