'py.test' is not recognized as an internal or external command, operable program or batch file
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.
amirhossein bagherian
Updated on June 28, 2022Comments
-
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 over 3 yearsplease add error in question to well understand your problem thanks.
-
alkasm over 3 yearswhat about
py -3 -m pytest
instead ofpy.test
? -
amirhossein bagherian over 3 yearswhat @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 over 3 yearsIt doesn't work. Still the same output: "'pytest' is not recognized as an internal or external command, operable program or batch file."
-
amirhossein bagherian over 3 yearsI 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 over 3 yearsOkay. Then try creating a virtual environment. Use these commands: pip install virtualenvwrapper-win and mkvirtualenv myVirtualEnv
-
nvt_dc over 3 yearsThe command prompt must now be like: (myVirtualEnv) C:\Users\<UserName>
-
nvt_dc over 3 yearsNow, 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 over 3 yearsAlso, 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 almost 2 yearspython -m pytest filename.py will run for specific file