6

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.

MrBean Bremen
  • 14,916
  • 3
  • 26
  • 46
Salvatore Avanzo
  • 2,656
  • 1
  • 21
  • 30
  • possible duplicate of [py.test -n => "py.test: error: unrecognized arguments: -n"](http://stackoverflow.com/questions/24198753/py-test-n-number-of-processes-py-test-error-unrecognized-arguments-n) – Salvatore Avanzo Sep 19 '14 at 12:07

4 Answers4

6

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.

user229044
  • 232,980
  • 40
  • 330
  • 338
Cecil Curry
  • 9,789
  • 5
  • 38
  • 52
2

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

Oleg
  • 81
  • 1
  • 4
0

Please try py.test --version and look at the output which explains where things are imported from, including plugins. Very likely are not running the py.test that you think you are running.

hpk42
  • 21,501
  • 4
  • 47
  • 53
0

I ran into this problem and figured out it was because of a really old setuptools (the default version that ships on Centos6.7)

pip list | grep setuptools
setuptools (0.6rc11)

So first upgrade setuptools

sudo pip install --upgrade setuptools

Then reinstall pytest and pytest-xdist

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

After this pytest was able to discover the xdist plugin.

Praetorian
  • 106,671
  • 19
  • 240
  • 328