python -m pytest: Run Tests with the Project on sys.path
Run pytest so your package imports actually resolve.
python -m pytest runs pytest as a module, which prepends the current directory to sys.path. This resolves many "module not found" collection errors that a bare pytest hits.
What it does
Runs the pytest module with the invoking interpreter and adds the working directory to sys.path (unlike the standalone pytest entry point). This makes local packages importable during test collection.
Common usage
Terminal
python -m pytest
python -m pytest tests/ -q
python -m pytest -k "auth and not slow" --maxfail=1Common CI error: ModuleNotFoundError on collection
A bare "pytest" can fail to import your package because the project root is not on sys.path. Switching to "python -m pytest" (or installing the package with pip install -e .) fixes it.
Terminal
# Failure with bare pytest:
# ModuleNotFoundError: No module named 'myapp'
# Fix:
python -m pytestRelated guides
python -m pip: Run pip for the Right InterpreterWhy python -m pip is safer than a bare pip in CI, how it guarantees you install into the intended interpreter…
pip install -e: Editable Installs ExplainedWhat an editable install does, when to use pip install -e in CI, and the build-backend errors editable instal…
python -c: Run a One-Liner in CIHow python -c runs a snippet of Python directly from the command line, common CI uses like version and import…