py.test vs. pytest: which command should you use?
Use pytest or python -m pytest for test runs, and understand the legacy py.test entry point and Python import-path differences.
Use pytest for new scripts and documentation. py.test is the historical command name; installations that provide both entry points run the same testing framework.
pytest tests/
python -m pytest tests/
Why older projects use py.test
The project originated in the py library. pytest 3.0 introduced the pytest command as the recommended spelling while retaining the older py.test entry point for compatibility. Seeing py.test in an old Makefile does not mean that the tests require a different framework.
Whether both commands are available depends on the installed distribution and environment. Check the interpreter and package version before assuming a missing executable means an old release:
python -m pytest --version
python -m pip show pytest
FAQ
What if only py.test is available?
Activate the intended virtual environment and check its installed pytest version. If it is an older installation, upgrade within the project’s supported dependency range using python -m pip install --upgrade pytest. A missing command can also be a PATH or environment mismatch, so upgrading is not always the fix.
Is python -m pytest identical to pytest?
The test runner is the same, but module invocation uses the selected python interpreter and normally adds the current directory to sys.path. That can change import resolution. Use it when you want to bind the run to a specific interpreter, and keep the invocation consistent between development and CI rather than relying on accidental import behavior.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan