forked from tox-dev/tox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use _TOX_PARALLEL_ENV environment variable to control the behavior
...but keep the TOX_PARALLEL_ENV variable for others to consume. The problem with using environment variables to let tox know it's being run as a parallel worker is the following: Either you don't pass the environment variable, but the test frameworks and test suites are unaware that tox is running in parallel. This makes it hard for cases like pytest-django: tox-dev#1139 Or you pass the environment variable, but it makes tox invoked within tox think it is a parallel worker even when it isn't. This makes it hard to test various tox plugins that invoke tox in their integration test suite: Fixes tox-dev#1444 By introducing two variables we can use one ("private", _TOX_PARALLEL_ENV) to control the behavior of tox (and don't pass it) and another ("public", TOX_PARALLEL_ENV) to let the tests and test frameworks know tox is running in parallel (and pass it by default).
- Loading branch information
Showing
9 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Fix nested tox execution in the parallel mode by separating the environment | ||
variable that let's tox know it is invoked in the parallel mode | ||
(``_TOX_PARALLEL_ENV``) from the variable that informs the tests that tox is | ||
running in parallel mode (``TOX_PARALLEL_ENV``). | ||
— by :user:`hroncok` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import subprocess | ||
import sys | ||
import textwrap | ||
|
||
from tox.util.main import MAIN_FILE | ||
|
||
|
||
def test_parallel_inception(tmpdir): | ||
# the outer config just has one env: graham | ||
content = textwrap.dedent( | ||
""" | ||
[tox] | ||
envlist = graham | ||
skipsdist = True | ||
[testenv] | ||
commands = | ||
python runner.py | ||
""" | ||
) | ||
outer_config = tmpdir / "tox.ini" | ||
outer_config.write_text(content, encoding="utf-8") | ||
|
||
# the inner config has 3 different envs, 1 of them is graham | ||
content = textwrap.dedent( | ||
""" | ||
[tox] | ||
envlist = graham,john,terry | ||
skipsdist = True | ||
[testenv] | ||
commands = | ||
python -c 'pass' | ||
""" | ||
) | ||
inner_dir = tmpdir / "inner" | ||
inner_dir.mkdir() | ||
inner_config = inner_dir / "tox.ini" | ||
inner_config.write_text(content, encoding="utf-8") | ||
|
||
# the outer test runs the inner tox and asserts all 3 envs were run | ||
content = textwrap.dedent( | ||
""" | ||
import os | ||
import subprocess | ||
import sys | ||
os.chdir("inner") | ||
cp = subprocess.run(("tox"), stdout=subprocess.PIPE, universal_newlines=True) | ||
sys.stdout.write(cp.stdout) | ||
assert "graham" in cp.stdout | ||
assert "john" in cp.stdout | ||
assert "terry" in cp.stdout | ||
""" | ||
) | ||
runner = tmpdir / "runner.py" | ||
runner.write_text(content, encoding="utf-8") | ||
|
||
with tmpdir.as_cwd(): | ||
process = subprocess.run( | ||
[sys.executable, MAIN_FILE, "-p", "all", "-o"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, # forces unicode on PY2 and PY3 alike | ||
) | ||
|
||
print(process.stdout) | ||
print(process.stderr, file=sys.stderr) | ||
|
||
assert process.returncode == 0 | ||
# 1 from the outer, 1 from the inner | ||
assert process.stdout.count("graham: commands succeeded") == 2 | ||
# those gentlemen are only inside | ||
assert process.stdout.count("john: commands succeeded") == 1 | ||
assert process.stdout.count("terry: commands succeeded") == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters