python并发执行测试_在pytest中可以并行执行相同的测试吗?

要重复测试执行,请在conftest.py中添加一个钩子:def pytest_collection_modifyitems(items):

numrepeats = 2

items.extend(items * (numrepeats - 1))

这将复制为执行而收集的每个测试numrepeats次。示例运行:

^{pr2}$

如果要使其可配置,请添加自定义cli参数:import pytest

def pytest_addoption(parser):

parser.addoption(' numrepeats', action='store', type=int, default=1)

def pytest_collection_modifyitems(items):

numrepeats = pytest.config.getoption(' numrepeats')

items.extend(items * (numrepeats - 1))

现在可以使用numrepeats调用测试,例如pytest numrepeats 5。在

至于对每个进程进行批处理测试(问题的第二部分),pytest-xdist还不支持它,请参见{a1}以及与之相关的所有内容。最近,添加了一些基本支持,如在单独进程中的单个模块或类中执行测试:dist=distmode set mode for distributing tests to exec environments.

each: send each test to all available environments.

load: load balance by sending any pending test to any

available environment. loadscope: load balance by

sending pending groups of tests in the same scope to

any available environment. loadfile: load balance by

sending test grouped by file to any available

environment. (default) no: run tests inprocess, don't

distribute.

但是,如果您想基于某些自定义条件来平衡测试,除了编写自己的调度程序impl之外,别无选择。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值