[FAQ]: The tox answer should recommend `poetry install --no-root` instead of `poetry install`
See original GitHub issue- I have searched the issues of this repo and believe that this is not a duplicate.
In the FAQ, there is a recommendation for how to use tox with Poetry. It suggests this tox.ini
:
[tox]
isolated_build = true
envlist = py27, py36
[testenv]
whitelist_externals = poetry
commands =
poetry install -v
poetry run pytest tests/
With this configuration, when a user runs tox:
- tox packages the project with Poetry.
- tox creates a virtual environment.
- tox installs the package it built, but not its dependencies (
inst-nodeps
). - tox calls
poetry install
, which installs the project dependencies, and then installs the project, as editable, overwriting what tox installed in step 3. - tox calls
poetry run pytest tests
which tests against the package as it exists in the working directory, not as it was packaged by Poetry.
To fix this, the recommended commands
should be:
commands =
poetry install --no-root -v
poetry run pytest tests/
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:30 (7 by maintainers)
Top Results From Across the Web
FAQ | Documentation | Poetry - Python dependency ...
Yes. By using the isolated builds tox provides, you can use it in combination with the PEP 517 compliant build system provided by...
Read more >tox-poetry-installer - PyPI
This is a plugin to unify two great projects in the Python ecosystem: the Tox automation project and the Poetry project/dependency manager.
Read more >python - How does tox install my poetry project on its virtual ...
Questions: tox usually install the packages with pip. Yet, I use poetry here. How can it install my package then? Does it build...
Read more >tox-poetry-installer - Python Package Health Analysis - Snyk
A plugin for Tox that lets you install test environment dependencies from the Poetry lockfile For more information about how to use this...
Read more >Implementing dependency management with Python Poetry
For some projects, you have development dependencies which are tools that you install while developing the project, but which should NOT be ...
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
I believe Poetry should be left out of
tox.ini
entirely. This is the pattern I would recommend:tox.ini
pyproject.toml
This is enabled by the
isolated_build = true
setting. This lets tox know to look intopyproject.toml
’sbuild-system
section, and delegates the build to the proper build backend, which in the case here is poetry obviously. This was always (as far as I can remember at least), clearly the case in both FAQ’s (poetry and tox), but then poetry’s FAQ muddies the water by recommendingcommands = poetry install
, which is a step back: it destroys the work done byisolated_build
.This isolated build feature is the new standard (look up PEP 517 and PEP 518), works also with setuptools, flit, etc.
The missing element here is about the development dependencies. How to let tox know what the dev dependencies are?
This can be solved by using the extras (which is a standard, i.e. specified by a PEP), this pattern is quite common nowadays and is guaranteed to work across many different tools (not only tox, and poetry).
On the other hand, generating a
requirements.txt
file (not a standard, there is no PEP specification) dynamically, feels unnecessary to me. And poetry’s owndev-dependencies
field is not a standard either, so tox doesn’t know how to handle it.But again, if one wants to go all-in with poetry and use all its features (even the non standard ones), feel free. But it means that you will have to work harder to make it cooperate with other tools that do follow standards. Which could be fine, maybe there isn’t even need for tox to begin with. Just running
poetry run pytest
could be perfectly good, no need for more.So my point is: in my opinion poetry’s FAQ on the topic of tox is misleading and shows a largely sub-optimal pattern.
I have been thinking for a while about writing a plugin for tox that would offer tox a way to automatically pick up poetry’s dev dependencies. Maybe that would put this issue to rest. Or maybe there’s already such a plugin? If you know of one, let us know.