要重复测试执行,请在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之外,别无选择。在