Fixes · Checked on 2026-10-07, with Python 3.13 and pytest 9.1
No module named pytest
The python you ran isn't the one pytest is installed in.
The error
PS C:\work\app> python -m pytest
C:\Users\you\AppData\Local\Programs\Python\Python313\python.exe: No module named pytest
The path at the start says which Python ran, and that's the clue.
Why it happens
python -m pytest runs the pytest installed in that Python. Every Python install and every virtual
environment has its own packages, and a project's pytest usually lives in its environment, such as
.venv. A shell that hasn't activated it, like the one a coding agent starts, runs the global Python
instead.
On Windows there can be several of each. On the machine we checked this on:
PS> where.exe python pytest
C:\Users\you\AppData\Local\Programs\Python\Python313\python.exe
C:\Users\you\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Users\you\AppData\Roaming\Python\Python314\Scripts\pytest.exe
python is 3.13, the second one is the Microsoft Store's stand-in, and the pytest
command belongs to a third, Python 3.14, so running pytest instead tests with a different Python
again.
The fix
Run the environment's own Python. It needs no activating:
.venv\Scripts\python -m pytest
In PowerShell, a quoted path needs the call operator:
& '.venv\Scripts\python.exe' -m pytest
Or install pytest into the Python you ran:
python -m pip install pytest
To see which Python a command runs:
python -c "import sys; print(sys.executable)"
How DMN learned it
It came up, and was fixed, in 5 of our own sessions. DMN kept the fix as one line:
The global Python313 `python` lacks pytest; run tests with `target/benchmark-venv/Scripts/python.exe -m
pytest ...` (in PowerShell prefix with `&` when quoting the path).
DMN reads your agents' past sessions on your machine. When the same error is fixed the same way in two or more of them, it keeps the fix as a one-line lesson. When the error turns up again, Claude Code is told the fix straight away, and any agent can search what earlier sessions found. How DMN keeps what agents learn.