nox session doesn't find pytest installed by poetry
See original GitHub issueI’m following along the Hypermodern Python series and it seems in Chapter 2, Test automation with Nox there is a conflict between nox
and poetry
. Specifically when I use the example noxfile.py
:
import nox
@nox.session(python=["3.8", "3.7"])
def tests(session):
session.run("poetry", "install", external=True)
session.run("pytest", "--cov")
I get the following error:
nox > Running session tests-3.8
nox > Creating virtual environment (virtualenv) using python3.8 in .nox/tests-3-8
nox > poetry install
Installing dependencies from lock file
No dependencies to install or update
- Installing testpkg (0.1.0)
nox > Program pytest not found.
nox > Session tests-3.8 failed.
(and the same for tests-3.7)
It seems that installing pytest
via poetry
as a dev dependency doesn’t put it on the path. In the previous section of Chapter 2, pytest
was invoked through poetry
and this does work in the nox
session as well:
session.run('poetry', 'run', 'pytest', '--cov')
Is this an issue with my setup or is it expected that pytest
can’t be run as a command when installed by poetry
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (7 by maintainers)
Top Results From Across the Web
How to use nox with poetry? - python - Stack Overflow
Currently, session.install doesn't support poetry and install just runs pip in the shell. You can activate poetry with a more general method ...
Read more >nox-poetry documentation
The session.install method automatically honors the Poetry lock file when installing dependencies. This allows you to manage packages used in Nox sessions ......
Read more >Hypermodern Python 6: CI/CD - Medium
In this sixth and last installment of the Hypermodern Python series, ... run: pip install poetry==1.0.5 ... Add the Nox session shown below....
Read more >Task runners - Scikit-HEP
Nox. Installing; Introduction; Parametrizing; Useful sessions. Lint; Tests; Docs; Build (pure Python). Examples. A task runner, like make (fully general), ...
Read more >Welcome to Nox — Nox 2022.11.21 documentation
import nox @nox.session def tests(session): session.install('pytest') session.run('pytest') ... For documentation on running nox , see Command-line usage.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Your question helped me find the problem. The nox version was 2019.5.30 which did not match what my other computer was using. I ended up actually reinstalling my Ubuntu instance (running as WSL on Windows 10) and have been worked through the same initialization steps again. I realized that the installation of nox didn’t quite work as expected. Running “pip install --user --upgrade nox” did complete the install, but then the nox keyword would return
So I realized I had installed via sudo which installed the 2019.5.30 version. The underlying issue is that using the pip method to install nox did not add it to PATH, so I just needed to add
to my .bashrc file and reload the shell. Now it seems to work as expected.
I created a corresponding issue.