on MAC OS X, py.test not recognized as a command

14,984

Solution 1

Got it worked finally! After downloading pytest, I ran the following commands and it worked like magic. I think,earlier, I missed putting "sudo" infront of the install command:

$python setup.py build
$sudo python setup.py install

The output said:

..
Installing py.test script to /usr/local/bin
Installing py.test-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pytest-2.6.4-py2.7.egg
..
Using /Users/admin/Library/Python/2.7/lib/python/site-packages
Finished processing dependencies for pytest==2.6.4

My .bash_profile contents, jfyr:

PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/System/Library/Frameworks/Python.framework/Versions/2.7/bin"
export PATH

Solution 2

On OS X you should do:

pip install -U pytest 

or

easy_install -U pytest

http://pytest.org/latest/getting-started.html

Solution 3

For those of us trying to avoid any and all use of sudo:

  1. Download from PyPI here and unpack.
  2. $ cd <pytest download folder>
  3. $python setup.py build
  4. $python setup.py install --user
  5. Wherever the installing output says the "py.test script" has been installed to, add to PATH in your .bash_profile (or .bashrc if you use that for environment variables).
  6. Confirm the setup worked via $py.test --version

Solution 4

pip3 install -U pytest is working with version Python 3.7

Share:
14,984
user2525211
Author by

user2525211

Updated on June 15, 2022

Comments

  • user2525211
    user2525211 almost 2 years

    On MAC OS X 10.10; I installed pytest 2.6.4; however in Terminal If I write py.test or even py.test --version; I get the error:

    -bash: py.test command not found
    

    (a) Am I missing anything? What do I do to make the pytest tool recognizable. I searched alot; but couldn't find any info except http://teckla.idyll.org/~t/transfer/py.test.html

    I checked in the PyCharm preferences, I don't see py.test interpreter listed there. However, pip freeze displays pytest 2.6.4 installed.

    (b) Is PYTHONPATH required to be set on MAC? Although I've seen setting it is not required on Windows.

    Appreciate any pointers to help me resolve this.


    Update: Contents of my bash_profile:

    echo export PATH="HOME/.rbenv/bin:$PATH"
    eval "$(rbenv init -)"
    
    PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
    PATH="/Users/admin/Library/Python/2.7/lib/python/site-packages:$PATH"
    PATH="/System/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH"
    export PATH