A tox4 plugin for reusing a virtualenv across multiple test environments.
Project description
tox-ignore-env-name-mismatch
Reuse virtualenvs with multiple tox
test environments.
If two environments have compatible specifications (basically, same deps
) and
use the same env_dir
, installing this plugin and setting
ignore_env_name_mismatch = true
will allow tox to use the same underlying
virtualenv for each test environment.
Usage
- Install
tox-ignore-env-name-mismatch
in the same environment astox
. - Set
ignore_env_name_mismatch = true
to opt-out of recreating the virtualenv when the cached name differs from the current env name.
- To always use this plugin, specify
requires = tox-ignore-env-name-mismatch
in the[tox]
section oftox.ini
Example
[tox]
envlist = py39,py310,py311,lint,format,types
requires = tox-ignore-env-name-mismatch
[testenv]
deps = pytest
commands = pytest {posargs}
[testenv:{lint,format,types}]
env_dir = {toxworkdir}{/}static
ignore_env_name_mismatch = true
deps =
black
flake8
mypy
commands =
lint: flake8 src tests
format: black --check src tests
types: mypy --strict src
see ./examples
directory for a working example including the tox configuration above.
Why??
Typically this usage pattern is seen with "auxillary" environments that
perform project operations, like linting, generating docs, or publishing
packages. Using different testenv
sections is a nice way to separate commands
and passenv
/ setenv
, but creating separate virtualenv that would otherwise
use identical dependencies is both a waste of time and space.
In tox 3, it was possible to achieve this behavior (with a bug and some caveats)
by simply having testenvs share an env_dir
. In tox 4, this hackaround was
properly fixed and now tox checks a cached {envdir}/.tox-info.json
and
recreates the virtualenv if the current testenv doesn't match what is cached.
This plugin allows a test environment to specifically opt-out of recreating the
virtualenv when only the env_name
.
This plugin only supports tox 4.
Motivation
People have been asking for this for at least 7 years and the core tox
project
is specifically not interested in supporting this use case in tox 4 (which is
fine, that's what plugins are for).
- [tox-dev/tox#2788] Re-use of virtual environments across envs in tox4 [2022, Github]
- Reuse environment on Tox 4 [2022, StackOverflow]
- tox multiple tests, re-using tox environment [2019, StackOverflow]
- [tox-dev/tox#425] Ability to share tox environments within a project [2016, Github]
- Tox tricks and patterns#Environment reuse [2015, Blog]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for tox-ignore-env-name-mismatch-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | af50f1efc76b8b90503006ffa0ea94543ebf2d377bfe92c9f5a5d8b0447457ff |
|
MD5 | f555077664daf50e5e5cb5e792e2f9f0 |
|
BLAKE2b-256 | 1a24a3cb2ff1fa7f8842ba150b7124faad062d4539b3498f755814d043bf07b3 |
Hashes for tox_ignore_env_name_mismatch-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eda5a4a85928baa1a8a8d85612b183ca63def49ef7019a1a8aa9a145e8f327dd |
|
MD5 | f5a4f2502b5ac80c4beb3dc352d24d26 |
|
BLAKE2b-256 | 5eb982c427c0c349f00897c9e0741c558b7e3b979f676f0eb9edf3a4aff68046 |