Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'Usecase 4' for poetry+tox #7346

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 55 additions & 4 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ allowlist_externals = poetry
commands_pre =
poetry install --no-root --sync
commands =
poetry run pytest tests/ --import-mode importlib
pytest tests/ --import-mode importlib
```

`tox` will create an `sdist` package of the project and uses `pip` to install it in a fresh environment.
Thus, dependencies are resolved by `pip` in the first place. But afterwards we run Poetry,
which will install the locked dependencies into the environment.
`tox` will create an `sdist` package of the project and use `pip` to install it in a fresh environment.
Thus, dependencies are resolved by `pip` in the first place. But afterwards we run Poetry, which will
install the locked dependencies into the environment.

#### Usecase #3
```ini
Expand All @@ -146,6 +146,57 @@ commands =
`tox` will not do any install. Poetry installs all the dependencies and the current package an editable mode.
Thus, tests are running against the local files and not the built and installed package.

#### Complex Usage with Dependency Groups

```ini
[tox]
isolated_build = true

[testenv]
allowlist_externals = poetry

[testenv:test]
commands_pre =
poetry install --no-root --sync --with test
commands =
pytest tests/

[testenv:style]
skip_install = true
commands_pre =
poetry install --no-root --sync --with style
commands =
flake8 src/
black --check src/

[testenv:typing]
skip_install = true
commands_pre =
poetry install --sync --with typing
commands =
mypy src/
```

In the `test` testenv, `tox` will create an `sdist` package of the project and use `pip` to install
it in a fresh environment.
Thus, dependencies are resolved by `pip` in the first place. But afterwards we run Poetry, which will
install the locked dependencies into the environment.

In the `style` testenv, `tox` will only create the virtual environment, and
again we will rely on Poetry to install requirements.
The project itself will not be installed at all, as `tox` uses `skip_install`
and poetry uses `--no-root`.

In the `typing` testenv, `tox` will only create the virtual environment, without installing the package,
and Poetry will be used to install requirements.
The project will be installed into the testenv by Poetry in addition to its
dependencies.

`poetry` is used to sync package dependencies and named dependency groups into
the `tox`-created virtual environments. This allows dependency groups to provide
dependencies for different `tox` environments, providing `test` to the `test`
testenv, `style` to the `style` env, and `typing` to the `typing` env.

### I don't want Poetry to manage my virtual environments. Can I disable it?

While Poetry automatically creates virtual environments to always work isolated
Expand Down