6

我已经在工作的 pytest 环境之上安装了 pytest-xdist:

pip install pytest-xdist

我收到了这个输出

Downloading/unpacking pytest-xdist
  Downloading pytest-xdist-1.10.tar.gz
  Running setup.py egg_info for package pytest-xdist

    no previously-included directories found matching '.hg'
Downloading/unpacking execnet>=1.1 (from pytest-xdist)
  Downloading execnet-1.2.0.tar.gz (163kB): 163kB downloaded
  Running setup.py egg_info for package execnet

    warning: no files found matching 'conftest.py'
Requirement already satisfied (use --upgrade to upgrade): pytest>=2.4.2 in /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages (from pytest-xdist)
Requirement already satisfied (use --upgrade to upgrade): py>=1.4.20 in /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages (from pytest>=2.4.2->pytest-xdist)
Installing collected packages: pytest-xdist, execnet
  Running setup.py install for pytest-xdist

    no previously-included directories found matching '.hg'
  Running setup.py install for execnet

    warning: no files found matching 'conftest.py'
Successfully installed pytest-xdist execnet
Cleaning up...

在这一点上,我试图并行运行我的测试套件

py.test -n 4

但我收到了这个输出

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

'py.test --version is' 的输出

This is pytest version 2.6.2, imported from /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest.pyc
setuptools registered plugins:
  pytest-capturelog-0.7 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_capturelog.pyc
  pytest-contextfixture-0.1.1 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_contextfixture.pyc
  pytest-cov-1.7.0 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_cov.pyc
  pytest-django-2.6.2 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_django/plugin.pyc
  pytest-pydev-0.1 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_pydev.pyc
  pytest-runfailed-0.3 at /Users/sal/Documents/code/Python/VirtualEnv/Spring/lib/python2.7/site-packages/pytest_runfailed.pyc

并且 pytest-xdist 实际上丢失了。

我错了什么?谢谢。

4

4 回答 4

6

user2412166一样,我遇到了同样的问题。xdist与user2412166 不同,我的解决方案是pytest_xdist-1.14.dist-info放宽pip3.

一些背景故事:为了安全起见,我在我的系统上运行严格,默认情况下umask禁止对用户的所有访问和对other用户的写访问:group

$ umask
027

虽然这通常是一件好事,但它也偶尔会给我带来麻烦。python-xdist通过pip3以下安装umask

$ sudo pip3 install pytest-xdist

...导致pip3禁止对非超级用户进行读取和执行访问——最好只有我

$ ls -l /usr/lib64/python3.4/site-packages/xdist
drwxr-x---   3 root root 4.0K 2016-04-10 01:19 xdist/
$ ls -l /usr/lib64/python3.4/site-packages/pytest_xdist-1.14.dist-info
drwxr-x---   3 root root 4.0K 2016-04-10 01:19 xdist/

虽然pip3这样做并没有错,py.test但(...可以说!)在插件检测期间默默地忽略而不是明确报告明显的权限问题是错误的。

通过递归地授予other用户对受影响的系统目录的读取和目录执行权限,可以轻松解决此问题:

$ chmod -R o+rX /usr/lib64/python3.4/site-packages/xdist
$ chmod -R o+rX /usr/lib64/python3.4/site-packages/pytest_xdist-1.14.dist-info

证明是命令行布丁:

$ ls -l /usr/lib64/python3.4/site-packages/xdist
drwxr-xr-x   3 root root 4.0K 2016-04-10 01:19 xdist/
$ ls -l /usr/lib64/python3.4/site-packages/pytest_xdist-1.14.dist-info
drwxr-xr-x   3 root root 4.0K 2016-04-10 01:19 xdist/
$ py.test --version
This is pytest version 2.8.7, imported from /usr/lib64/python3.4/site-packages/pytest.py
setuptools registered plugins:
  pytest-xdist-1.14 at /usr/lib64/python3.4/site-packages/xdist/looponfail.py
  pytest-xdist-1.14 at /usr/lib64/python3.4/site-packages/xdist/plugin.py
  pytest-xdist-1.14 at /usr/lib64/python3.4/site-packages/xdist/boxed.py

因此,不清楚的地方变得清晰,调试了错误,缓慢的测试迅速并行化。

于 2016-04-10T06:25:52.307 回答
2

我有同样的问题。问题不在于版本。不知何故 py.test 看不到 xdist 在哪里。这对我有用:

pip install pytest --user
pip install pytest-xdist --user

导出 PATH=$HOME/.local/bin:$PATH

于 2015-09-26T00:04:42.663 回答
0

请尝试py.test --version查看输出,其中解释了从何处导入内容,包括插件。很可能没有运行py.test您认为正在运行的。

于 2014-09-19T10:59:33.910 回答
0

我遇到了这个问题,发现这是因为一个非常旧setuptools的(Centos6.7 上的默认版本)

pip list | grep setuptools
setuptools (0.6rc11)

所以先升级setuptools

sudo pip install --upgrade setuptools

然后重新安装pytestpytest-xdist

sudo pip install --upgrade pytest pytest-xdist --force-reinstall

在此之后pytest能够发现xdist插件。

于 2016-08-25T21:27:06.643 回答