Skip to main content

用于并行和并发测试的 pytest 插件

项目描述

pytest 并行

用于并行和并发测试的 pytest 插件

什么?

这个插件可以使用多处理(并行)和多线程(并发)快速运行测试。

为什么?

pytest-xdist非常适合运行以下测试:

  1. 不是线程安全的
  2. 多线程时性能不佳
  3. 需要状态隔离

pytest-parallel对于某些用例(如 Selenium 测试)更好:

  1. 可以是线程安全的
  2. 可以对 http 请求使用非阻塞 IO 来提高性能
  3. 在 Python 环境中管理很少或没有状态

简而言之,pytest-xdist并行pytest-parallel性是并行性和并发性。

要求

  • Python3 版本 [3.6+]
  • 适用于 Unix 或 Mac--workers
  • 适用于 Unix、Mac 或 Windows--tests-per-worker

安装

pip install pytest-parallel

选项

  • workers(可选)- 启动最大工作人员(又名进程)。可以是正整数,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

注意

从 Python 3.8 开始,在 macOS 上强制分叉行为以牺牲安全为代价。

Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725.

资源

执照

麻省理工学院

下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pytest-parallel-0.1.1.tar.gz (9.5 kB 查看哈希)

已上传 source

内置分布

pytest_parallel-0.1.1-py3-none-any.whl (7.0 kB 查看哈希

已上传 py3