unittest是python的官方库,功能较少,pytest是第三方库,是基于unittest的扩展框架,可支持多种插件,目前有100多种,功能强大。
pytest可兼容unittest写的用例,代码完全不用更改。
一、用例编写方面
1、测试文件:
unittest必须:test*.py,pytest默认定义方式:test_*.py或者*_test.py,也可通过配置文件pytest.ini,配置块[python],配置项pytest_files自定义;
2、测试类:
unittest不要求测试类命名,pytest默认以Test开头,也可自定义;
3、测试方法:
unittest必须以test开头,非test_