用于并行和并发测试的pytest插件
pytest-parallel的Python项目详细描述
并行pytest
用于并行和并发测试的pytest插件
什么?
这个插件使得使用多处理(并行)和多线程(并发)快速运行测试成为可能。
为什么?
pytest-xdist
非常适合运行以下测试:
- 不是线程安全的
- 多线程时性能不佳
- 需要状态隔离
pytest-parallel
对于某些用例(如selenium测试)来说更好:
- 可以是线程安全的
- 可以对http请求使用非阻塞io以使其具有性能
- 在python环境中很少或根本不管理状态
简单地说,pytest-xdist
执行并行,而pytest-parallel
执行并行和并发。
要求
- python3版本[3.6+]
- 用于
--workers
的Unix或Mac
- UNIX、Mac或Windows for
--tests-per-worker
安装
pip install pytest-parallel
选项
workers
(可选)-要启动的最大工作线程(aka进程)。可以是正整数,也可以是auto
每个核心使用一个工作进程。默认为1。tests-per-worker
(可选)-每个工作进程的最大并发测试数。可以是正整数,也可以是auto
将测试平均分配给最多50个并发测试。默认为1。
示例
# runs 2 workers with 1 test per worker at a time pytest --workers 2# runs 4 workers (assuming a quad-core machine) with 1 test per worker pytest --workers auto # runs 1 worker with 4 tests at a time pytest --tests-per-worker 4# runs 1 worker with up to 50 tests at a time pytest --tests-per-worker auto # runs 2 workers with up to 50 tests per worker pytest --workers 2 --tests-per-worker auto
许可证
麻省理工学院