Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest doesn't recognize -n option after pytest-xdist installation

I have installed pytest-xdist on top of a working pytest environment :

pip install pytest-xdist

and I have received this output

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...

at this point I have tried to run my test suite in parallel

py.test -n 4

but I received this output instead

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

Output of '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

and pytest-xdist is effectively missing.

What I was wrong? Thanks.

like image 511
Salvatore Avanzo Avatar asked Sep 18 '14 14:09

Salvatore Avanzo


2 Answers

Like user2412166, I suffered the same issue. Unlike user2412166, the solution in my case was to relax the permissions on the xdist and pytest_xdist-1.14.dist-info system directories installed by pip3.

Some backstory: For security, I run a strict umask on my system prohibiting all access to other users and write access to group users by default:

$ umask
027

While this is usually a good thing, it also occasionally gets me into trouble. Installing python-xdist via pip3 under this umask:

$ sudo pip3 install pytest-xdist

...resulted in pip3 prohibiting read and execution access to non-superusers – which had better be only me:

$ 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/

While pip3 was not wrong in doing so, py.test was (...arguably!) wrong in silently ignoring rather than explicitly reporting an obvious permissions issue during plugin detection.

This was trivially fixable by recursively granting other users both read and directory execution permissions for the afflicted system directories:

$ 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

The proof is the command-line pudding:

$ 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

Thus was the unclear made clear, the buggy debugged, and the slow tests parallelized quickly.

like image 64
Cecil Curry Avatar answered Oct 24 '22 06:10

Cecil Curry


I had the same problem. The problem is not with the version. Somehow py.test cannot see where xdist is. Here's what worked for me:

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

export PATH=$HOME/.local/bin:$PATH

like image 21
Oleg Avatar answered Oct 24 '22 06:10

Oleg