diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 569584daf..5d7eae23c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -50,6 +50,7 @@ Mark Hirota Matt Good Matt Jeffery Mattieu Agopian +Michael Manganiello Mikhail Kyshtymov Monty Taylor Morgan Fainberg diff --git a/docs/changelog/1139.feature.rst b/docs/changelog/1139.feature.rst new file mode 100644 index 000000000..b8385004c --- /dev/null +++ b/docs/changelog/1139.feature.rst @@ -0,0 +1 @@ +tox will inject the ``TOX_PARALLEL_ENV`` environment variable, set to the current running tox environment name, only when running in parallel mode. diff --git a/docs/config.rst b/docs/config.rst index 848700e0e..f3aa8c912 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -932,6 +932,7 @@ tox will inject the following environment variables that you can use to test tha - ``TOX_ENV_NAME`` is set to the current running tox environment name - ``TOX_ENV_DIR`` is set to the current tox environments working dir. - ``TOX_PACKAGE`` the packaging phases outcome path (useful to inspect and make assertion of the built package itself). +- ``TOX_PARALLEL_ENV`` is set to the current running tox environment name, only when running in parallel mode. :note: this applies for all tox envs (isolated packaging too) and all external commands called (e.g. install command - pip). diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index e6e864bbf..bf4252e36 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -659,7 +659,15 @@ def passenv(testenv_config, value): # Flatten the list to deal with space-separated values. value = list(itertools.chain.from_iterable([x.split(" ") for x in value])) - passenv = {"PATH", "PIP_INDEX_URL", "LANG", "LANGUAGE", "LD_LIBRARY_PATH", "TOX_WORK_DIR"} + passenv = { + "PATH", + "PIP_INDEX_URL", + "LANG", + "LANGUAGE", + "LD_LIBRARY_PATH", + "TOX_WORK_DIR", + str(PARALLEL_ENV_VAR_KEY), + } # read in global passenv settings p = os.environ.get("TOX_TESTENV_PASSENV", None) diff --git a/tests/unit/config/test_config.py b/tests/unit/config/test_config.py index ba00b06c5..00524bc48 100644 --- a/tests/unit/config/test_config.py +++ b/tests/unit/config/test_config.py @@ -19,6 +19,7 @@ is_section_substitution, parseconfig, ) +from tox.config.parallel import ENV_VAR_KEY as PARALLEL_ENV_VAR_KEY from tox.venv import VirtualEnv @@ -1047,6 +1048,7 @@ def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat): assert "LANG" in envconfig.passenv assert "LANGUAGE" in envconfig.passenv assert "LD_LIBRARY_PATH" in envconfig.passenv + assert PARALLEL_ENV_VAR_KEY in envconfig.passenv assert "A123A" in envconfig.passenv assert "A123B" in envconfig.passenv