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

為{幸葍}努か 提交于 2019-12-08 05:37:47

问题


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

回答1:


On OS X you should do:

pip install -U pytest 

or

easy_install -U pytest

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




回答2:


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



回答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


来源:https://stackoverflow.com/questions/28098876/on-mac-os-x-py-test-not-recognized-as-a-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!