简体   繁体   中英

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

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

On OS X you should do:

pip install -U pytest 

or

easy_install -U pytest

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

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

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

pip3 install -U pytest 使用 Python 3.7 版本

I had a problem installing pytest on Mac M1 but I followed the python pip documentation and it worked. What i did was:

  • istalled pip via command in Pycharm terminal (I use pycharm): python3 -m pip install pytest

  • after installation I run the pytest from the terminal with a command : python3 -m pytest "name_of_the_file.py"

And that works. On Mac I need to prefix all commands with "python3" cause I guess Mac has its own inbuild Python but thats Python 2 so in order to run code on my Pycharm, which was Python 3 , I need that prefix in the command... not sure though I am a newbie but something along those lines I guess

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM