背景
本文总结如何指定pytest当次运行的覆盖范围。总体来说,可以指定运行单个测试目录,单个文件,单个测试类,单个测试类中的方法,单个函数。而这些指定仅和一个参数有关。
说明
首先看示例程序的目录结构:
以示例说明:
# 指定运行单个测试目录
pytest.main(['./test_case'])
# 指定运行单个测试文件
pytest.main(['./test_case/test_func.py'])
# 指定运行测试类
pytest.main(['./test_case/test_func.py::TestFunc'])
# 指定运行测试类中的某个方法
pytest.main(['./test_case/test_func.py::TestFunc::test_add_by_class'])
# 指定运行单个测试函数
pytest.main(['./test_case/test_func.py::test_add_by_func_aaa'])