From 0187833505e25d950830934c0e250baef6c2f858 Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Mon, 14 Jan 2019 17:55:37 -0300 Subject: [PATCH 1/2] Inject TOX_PARALLEL_ENV environment variables To allow other libraries, or projects, to know if Tox is running in parallel mode, add the `TOX_PARALLEL_ENV` environment variable to the list of injected variables. Particularly, this is useful for `pytest-django` to know if Tox is running in parallel mode, to rename test databases [0]. [0] https://github.com/pytest-dev/pytest-django/pull/680 --- CONTRIBUTORS | 1 + docs/changelog/1139.feature.rst | 1 + docs/config.rst | 1 + src/tox/config/__init__.py | 10 +++++++++- tests/unit/config/test_config.py | 2 ++ 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/1139.feature.rst 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..191359c63 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", + 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 From 12a77f60e98ca4ba3163ac6120c2903badf90ebc Mon Sep 17 00:00:00 2001 From: Michael Manganiello Date: Tue, 15 Jan 2019 09:08:21 -0300 Subject: [PATCH 2/2] Use strings (bytestrings in Python 2) in passenv whitelist --- src/tox/config/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tox/config/__init__.py b/src/tox/config/__init__.py index 191359c63..bf4252e36 100644 --- a/src/tox/config/__init__.py +++ b/src/tox/config/__init__.py @@ -666,7 +666,7 @@ def passenv(testenv_config, value): "LANGUAGE", "LD_LIBRARY_PATH", "TOX_WORK_DIR", - PARALLEL_ENV_VAR_KEY, + str(PARALLEL_ENV_VAR_KEY), } # read in global passenv settings