|
| 1 | +from __future__ import absolute_import, unicode_literals |
| 2 | + |
| 3 | +import subprocess |
| 4 | +import sys |
| 5 | +import textwrap |
| 6 | + |
| 7 | +from tox.util.main import MAIN_FILE |
| 8 | + |
| 9 | + |
| 10 | +def test_parallel_inception(tmpdir): |
| 11 | + # the outer config just has one env: graham |
| 12 | + content = textwrap.dedent( |
| 13 | + """ |
| 14 | + [tox] |
| 15 | + envlist = graham |
| 16 | + skipsdist = True |
| 17 | +
|
| 18 | + [testenv] |
| 19 | + commands = |
| 20 | + python runner.py |
| 21 | + """ |
| 22 | + ) |
| 23 | + outer_config = tmpdir / "tox.ini" |
| 24 | + outer_config.write_text(content, encoding="utf-8") |
| 25 | + |
| 26 | + # the inner config has 3 different envs, 1 of them is graham |
| 27 | + content = textwrap.dedent( |
| 28 | + """ |
| 29 | + [tox] |
| 30 | + envlist = graham,john,terry |
| 31 | + skipsdist = True |
| 32 | +
|
| 33 | + [testenv] |
| 34 | + commands = |
| 35 | + python -c 'pass' |
| 36 | + """ |
| 37 | + ) |
| 38 | + inner_dir = tmpdir / "inner" |
| 39 | + inner_dir.mkdir() |
| 40 | + inner_config = inner_dir / "tox.ini" |
| 41 | + inner_config.write_text(content, encoding="utf-8") |
| 42 | + |
| 43 | + # the outer test runs the inner tox and asserts all 3 envs were run |
| 44 | + content = textwrap.dedent( |
| 45 | + """ |
| 46 | + import os |
| 47 | + import subprocess |
| 48 | + import sys |
| 49 | +
|
| 50 | + os.chdir("inner") |
| 51 | + cp = subprocess.run(("tox"), stdout=subprocess.PIPE, encoding="utf-8") |
| 52 | + sys.stdout.write(cp.stdout) |
| 53 | + assert "graham" in cp.stdout |
| 54 | + assert "john" in cp.stdout |
| 55 | + assert "terry" in cp.stdout |
| 56 | + """ |
| 57 | + ) |
| 58 | + runner = tmpdir / "runner.py" |
| 59 | + runner.write_text(content, encoding="utf-8") |
| 60 | + |
| 61 | + with tmpdir.as_cwd(): |
| 62 | + process = subprocess.run( |
| 63 | + [sys.executable, MAIN_FILE, "-p", "all", "-o"], |
| 64 | + stdout=subprocess.PIPE, |
| 65 | + stderr=subprocess.PIPE, |
| 66 | + encoding="utf-8", |
| 67 | + ) |
| 68 | + |
| 69 | + print(process.stdout) |
| 70 | + print(process.stderr, file=sys.stderr) |
| 71 | + |
| 72 | + assert process.returncode == 0 |
| 73 | + # 1 from the outer, 1 from the inner |
| 74 | + assert process.stdout.count("graham: commands succeeded") == 2 |
| 75 | + # those gentlemen are only inside |
| 76 | + assert process.stdout.count("john: commands succeeded") == 1 |
| 77 | + assert process.stdout.count("terry: commands succeeded") == 1 |
0 commit comments