Python Pytest不';安装pytest xdist后无法识别-n选项
我已在一个正常工作的pytest环境上安装了pytest xdist:Python Pytest不';安装pytest xdist后无法识别-n选项,python,pytest,xdist,pytest-xdist,Python,Pytest,Xdist,Pytest Xdist,我已在一个正常工作的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 matc
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--版本为”的输出
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实际上丢失了
我错了什么?谢谢。请尝试
py.test--version
并查看输出,其中解释了从何处导入内容,包括插件。很可能您没有运行您认为正在运行的py.test
我也有同样的问题。问题不在于版本。不知何故,py.test无法看到xdist的位置。以下是对我有效的方法:
pip安装pytest--用户pip安装pytest xdist--用户 export PATH=$HOME/.local/bin:$PATH就像,我遇到了同样的问题。与User2411266不同,在我的案例中,解决方案是放松对
xdist
和pytest\u xdist-1.14.dist info
由pip3
安装的系统目录的权限
一些后台故事:为了安全起见,我在我的系统上运行了一个严格的umask
,默认情况下禁止所有对其他
用户的访问和对组
用户的写访问:
$ umask
027
虽然这通常是件好事,但偶尔也会给我带来麻烦。通过pip3
在此umask
下安装python xdist
:
$ sudo pip3 install pytest-xdist
…导致pip3
禁止对非超级用户进行读取和执行访问–最好只有我一个人:
虽然pip3
这样做并没有错,py.test
在插件检测期间默默忽略而不是显式报告明显的权限问题(…可以说!)是错误的
通过递归地为受影响的系统目录授予其他
用户读取和目录执行权限,这是可以解决的:
$ 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
因此,不清楚的地方被弄清楚了,错误被调试了,缓慢的测试很快并行化了。我遇到了这个问题,并发现这是因为一个非常旧的
setuptools
(Centos6.7上提供的默认版本)
因此,首先升级setuptools
sudo pip install --upgrade setuptools
然后重新安装pytest
和pytest xdist
sudo pip install --upgrade pytest pytest-xdist --force-reinstall
在此之后,
pytest
能够发现xdist
插件。我已经在我的问题中添加了“py.test--version”输出。看起来您正在安装和运行的环境有问题。可能是
sudo pip install --upgrade setuptools
sudo pip install --upgrade pytest pytest-xdist --force-reinstall