跳过主要内容

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

项目描述

pytest-parallel

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

是什么?

此插件通过多进程(并行)和多线程(并发)使快速运行测试成为可能。

为什么?

pytest-xdist 适用于运行以下测试

  1. 不是线程安全的
  2. 在多线程下表现不佳
  3. 需要状态隔离

pytest-parallel 适用于某些用例(如Selenium测试),这些用例

  1. 可以线程安全
  2. 可以使用非阻塞IO进行http请求以提高性能
  3. 在Python环境中管理少量或无状态

简单来说,pytest-xdist 执行并行,而 pytest-parallel 执行并行和并发。

要求

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

安装

pip安装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.

来源

许可协议

MIT

项目详情


下载文件

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

源分布

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

上传时间

构建分布

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

上传时间 Python 3

由以下支持