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
runner = ignore_env_name_mismatch will allow tox to use the same underlying
virtualenv for each test environment.
Development status: EXPRIMENTAL - The API is evolving and things are breaking. Please vendor the plugin as described below, or you will get broken.
Usage
- Install
tox-ignore-env-name-mismatchin the same environment astox. - Set
runner = ignore_env_name_mismatchin a testenv to opt-out of recreating the virtualenv when the env name changes.
To always use this plugin:
Vendor
- copy
src/tox_ignore_env_name_mismatch.pyto the root of your project directory astoxfile.py
This uses the tox4's new "inline plugin" approach instead of relying on the provisioning system (which can be disabled via CLI).
Install/provision
[tox]
min_version = 4.3.3
requires =
tox-ignore-env-name-mismatch ~= 0.2.0
This will cause tox to provision a new virtualenv for tox itself and other
dependencies named in the
requires key if the current
environment does not meet the specification.
Pinning the plugin to a minor version is highly recommended to avoid breaking changes.
NOTE: tox < 4.3.3 had a bug which prevented this type of installation.
Example
[tox]
envlist = py39,py310,py311,lint,format,types
min_version = 4.3.3
requires =
tox-ignore-env-name-mismatch ~= 0.2.0
[testenv]
deps = pytest
commands = pytest {posargs}
[testenv:{lint,format,types}]
env_dir = {toxworkdir}{/}static
runner = ignore_env_name_mismatch
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 differs.
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]
Changelog
v0.2 - 2023-01-15
[BREAKING] #3 Rewrite plugin to use Public API
To upgrade to v0.2, change ignore_env_name_mismatch = true to runner = ignore_env_name_mismatch.
v0.1 - 2023-01-14
Initial Release
Metadata
Release files for tox-ignore-env-name-mismatch 0.2.0.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tox-ignore-env-name-mismatch-0.2.0.post2.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tox_ignore_env_name_mismatch-0.2.0.post2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.4 kB
Release files / tox-ignore-env-name-mismatch-0.2.0.post2.tar.gz
| Download URL | tox-ignore-env-name-mismatch-0.2.0.post2.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cafb3a1ab8fe5706d4a32c28a63585bb4069e34a4e7becfa3d3f332d5f9d8ffb
|
|
BLAKE2b-256 checksum How to use checksums |
7ce42388bde7c6a4764679086edf5764ed78ddfa9e910d6771d7114138f206dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|
Release files / tox_ignore_env_name_mismatch-0.2.0.post2-py3-none-any.whl
| Download URL | tox_ignore_env_name_mismatch-0.2.0.post2-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
855925d911ecdda15be4325bab431460e4c2b98b5b467ff12d4fce799bdfa3c9
|
|
BLAKE2b-256 checksum How to use checksums |
40a6fbbab485ca9ea983b56cc19f4a62bd1030b5d0db1daf7dd973a202e682f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.1
|