本文转自测试人社区,原文链接:https://ceshiren.com/t/topic/30129
Python代码执行pytest
- 使用main函数
- 使用python -m pytest 调用pytest (jenkins持续集成用到)
python代码执行pytest-main函数
if __name__ == '__main__':
#1、运行当前目录下所有符合规则的用例,包括子目录(test_*.py 和*_test.py)
pytest.main()
#2、运行test_mark1.py::test_dkej模块中的某一条用例,打印详细输出日志
pytest.main(['test_mark1.py::test_dkej','-vs'])
#3、运行某个标签(自定义标记的某个标签)
pytest.main(['test_mark1.py','-vs','-m','dkej'])
运行方式
python test_*.py
获取更多软件测试知识

本文介绍了如何在Python中利用pytest进行测试,包括在main函数中执行所有符合规则的测试用例、指定单个用例执行以及根据自定义标记筛选测试。重点讲解了jenkins持续集成环境下的应用和命令行参数的使用。
1049

被折叠的 条评论
为什么被折叠?



