'py.test' is not recognized as an internal or external command, operable program or batch file

10,465

Solution 1

Getting the same problem, but it has been solved with the below command

python -m pytest

Solution 2

i am learning python with head first python book, i have been trying to use pytest module but was, not working and even search online everywhere but i could not find the solution the problem but some how, i manage to figure it out. so here's the solution the current version of pytest is version 6.2.2 unfortunately if use it with py.test --pep8 it will not work because it has been deprecated the simple solution is to use this version pip install pytest==2.9.1 and when it's successfully installed when you tried with the py.test --pep8 it will work.

Share:
10,465
amirhossein bagherian
Author by

amirhossein bagherian

Updated on June 28, 2022

Comments

  • amirhossein bagherian
    amirhossein bagherian almost 2 years

    I started learning python recently and I know my problem may not be sth complicated. I issued below command from my Windows cmd to install pytest framework and its required dependencies

    py -3 -m pip install pytest

    and then issued: py -3 -m pip install pytest-pep8

    to install pep8 plug-in and required dependencies. Both commands were done successfully.

    But when I want to run pytest by py.test --pep8 exp1.py command; I get mentioned error.

    any ideas?

    • Muhammad Rizwan Munawar
      Muhammad Rizwan Munawar over 3 years
      please add error in question to well understand your problem thanks.
    • alkasm
      alkasm over 3 years
      what about py -3 -m pytest instead of py.test ?
    • amirhossein bagherian
      amirhossein bagherian over 3 years
      what @alkasm says seems to work. test session starts but can't collect item(i.e. my program) and i receive about 15 lines error that i don't exactly understand the problem.
  • amirhossein bagherian
    amirhossein bagherian over 3 years
    It doesn't work. Still the same output: "'pytest' is not recognized as an internal or external command, operable program or batch file."
  • amirhossein bagherian
    amirhossein bagherian over 3 years
    I was thinking the same way when i saw the output. But pytest and pep8 plug-in were installed successfully and are avaible in C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Lib\site-packages\pytest\ address in my pc. But when i issue "pytest --version" command, i get the output i mentioned as my question name in this page.
  • nvt_dc
    nvt_dc over 3 years
    Okay. Then try creating a virtual environment. Use these commands: pip install virtualenvwrapper-win and mkvirtualenv myVirtualEnv
  • nvt_dc
    nvt_dc over 3 years
    The command prompt must now be like: (myVirtualEnv) C:\Users\<UserName>
  • nvt_dc
    nvt_dc over 3 years
    Now, reinstall pytest and pep8 using the same commands you used before and now, try running your script by navigating to the folder where your script is, using cd command and then using pytest --pep8 exp1.py
  • nvt_dc
    nvt_dc over 3 years
    Also, note that before installing pytest and pep8 in the virtual environment, you must consider uninstalling them from the global environment (your normal cmd). Use the following commands to uninstall: py -3 -m pip uninstall pytest and py -3 -m pip uninstall pytest-pep8
  • Gudwlk
    Gudwlk almost 2 years
    python -m pytest filename.py will run for specific file