pytest-repeat¶
pytest-repeat 是一个 pytest 插件, 可以将用例重复执行特定次数。
重复的次数通过标记 repeat
来指定:
# test_repeat_count.yaml
name: 一个简单的用例
mark:
- repeat: 5
steps:
- sleep: 0.01
执行结果:
(.venv) C:\demo\pytest-yaml-demo>pytest -v
============================= test session starts ==============================
platform win32 -- Python 3.12.0, pytest-8.2.2, pluggy-1.5.0
cachedir: .pytest_cache
rootdir: C:\demo\pytest-yaml-demo
configfile: pytest.ini
plugins: repeat-0.9.3, yaml-1.1.1
collected 5 items
tests/plugins/test_repeat_count.yaml::一个简单的用例[1-5] PASSED
tests/plugins/test_repeat_count.yaml::一个简单的用例[2-5] PASSED
tests/plugins/test_repeat_count.yaml::一个简单的用例[3-5] PASSED
tests/plugins/test_repeat_count.yaml::一个简单的用例[4-5] PASSED
tests/plugins/test_repeat_count.yaml::一个简单的用例[5-5] PASSED
============================== 5 passed in 0.09s ===============================