要启用并行测试,必须安装pytest-xdist
,并使用将-nauto
选项传递给pytest
以使用所有可用的cpu。我希望在默认情况下启用-nauto
,但仍将pytest-xdist
设为可选。所以这行不通:
[pytest]
addopts = -nauto
如果安装了pytest-xdist
,是否有一种方法可以在默认情况下启用pytest并行性?(如果需要,还可以使用pytest -n0
再次禁用它。)
我想一定要写某种conftest.py
钩子?{{a2插件可能安装得太晚了,但是^安装插件后}可能太晚了。此外,我不确定在那个时候如何添加选项(或者如何配置直接操纵xdist)。在
您可以检查
xdist
选项组是否定义了numprocesses
参数。这表示pytest-xdist
已安装,并且将处理该选项。如果不是这样,那么您自己的伪参数将确保该选项为pytest
(并安全地忽略):现在您可以在
^{pr2}$pytest.ini
中保留该选项,即使没有安装pytest-xdist
;但是,您需要使用long选项:原因是短选项是为
pytest
本身保留的,所以上面的代码没有定义或使用它。如果你真的需要做空期权,你必须求助于私人方法:现在可以在配置中使用short选项:
相关问题 更多 >
编程相关推荐