【pytest】(四) pytest的一些其他的运行用法

简介: 【pytest】(四) pytest的一些其他的运行用法

1. 可以设置当失败N个后停止测试


pytest -x 是当第一个失败产生后,停止

pytest --maxfail=2, 这里就是当失败2个用例后,停止测试


2.pytest 在命令行模式下支持多种方式运行和选择运行


  • pytest test_mod.py 运行这个文件(模块)


  • pytest testing/ 运行指定目录下的测试文件


3. 指定运行文件下具体类下的具体方法,用:: 分隔 文件、类、 方法


pytest test_mod.py::TestClass::test_method


4.pytest中同样提供了main() 来函数来执行测试用例


import pytest
def test_main():
    assert 5 != 5
if __name__ == '__main__':
    pytest.main()


sublime, ctrl + b 即可运行


5.在main()下运行指定目录文件,也可以加参数,比如


import pytest
def test_main():
    assert 5 != 5
if __name__ == '__main__':
    pytest.main("d:/pyse/pytest/")  # 指定测试目录
相关文章
|
11月前
|
测试技术 Python
Pytest简单介绍
Pytest简单介绍
59 0
|
测试技术
pytest conftest.py和fixture的配合使用
pytest conftest.py和fixture的配合使用
|
负载均衡 监控 测试技术
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
162 0
pytest学习和使用20-pytest如何进行分布式测试?(pytest-xdist)
|
测试技术 Python
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
108 0
pytest学习和使用17-Pytest如何重复执行用例?(pytest-repeat)
|
测试技术
pytest学习和使用9-fixture中conftest.py如何使用?
pytest学习和使用9-fixture中conftest.py如何使用?
111 0
pytest学习和使用9-fixture中conftest.py如何使用?
|
测试技术 Python
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
77 0
pytest学习和使用10-Pytest中的测试用例如何跳过执行?
|
测试技术
pytest学习和使用5-Pytest和Unittest中的断言如何使用?
pytest学习和使用5-Pytest和Unittest中的断言如何使用?
74 0
pytest学习和使用5-Pytest和Unittest中的断言如何使用?
|
Python
pytest学习和使用3-对比unittest和pytest脚本在pycharm中运行的方式
pytest学习和使用3-对比unittest和pytest脚本在pycharm中运行的方式
95 0
pytest学习和使用3-对比unittest和pytest脚本在pycharm中运行的方式