py.test 如何使用多核?

How to use multiple cores with py.test?

查看 py.test documentation 似乎传递 -n NUM 将指定要使用的核心数。

我的经验如下:

usage: py.test [options] [file_or_dir] [file_or_dir] [...]
py.test: error: unrecognized arguments: -n

如果我尝试在 pytest.ini 中指定它(这是我的偏好),我会得到相同的结果。

我正在将 addopts = -n4 添加到 ini 文件,这似乎是文档所要求的。

我正在使用 py.test 2.8,我已经尝试了 python 2 和 python 3。

您需要安装xdist

pip install pytest-xdist