Skip to content

Commit 43d65b1

Browse files
authored
various fixes related to sub-process handling (#1186)
1 parent ef9c0ca commit 43d65b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+813
-369
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ variables:
55
CI_NAME: Azure Pipelines
66
CI_BUILD_ID: $(Build.BuildId)
77
CI_BUILD_URL: "https://toxdev.visualstudio.com/tox/_build/results?buildId=$(Build.BuildId)"
8-
PYTEST_ADDOPTS: "-vv -ra --showlocals"
8+
PYTEST_ADDOPTS: "-v -v -ra --showlocals"
99
GIT_BRANCH: $[ coalesce(variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranchName'], 'not-found') ]
1010
GIT_COMMIT_SHA: $[ coalesce(variables['System.PullRequest.SourceCommitId'], variables['Build.SourceVersion'], 'not-found') ]
1111

docs/changelog/1137.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed bug of children process calls logs clashing (log already exists) - by :user:`gaborbernat`

docs/changelog/1139.feature.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
tox will inject the ``TOX_PARALLEL_ENV`` environment variable, set to the current running tox environment name, only when running in parallel mode.
1+
tox will inject the ``TOX_PARALLEL_ENV`` environment variable, set to the current running tox environment name,
2+
only when running in parallel mode. - by :user:`gaborbernat`

docs/changelog/1143.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Parallel children now save their output to a disk logfile - by :user:`gaborbernat`

docs/changelog/1150.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Interpreter discovery and virtualenv creation process calls that failed will now print out on the screen their output
2+
(via the logfile we automatically save) - by :user:`gaborbernat`

docs/changelog/1159.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Parallel children now are added to ``--result-json`` - by :user:`gaborbernat`

docs/changelog/1163.doc.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Add a ``poetry`` examples to packaging.
1+
Add a ``poetry`` examples to packaging - by :user:`gaborbernat`

docs/changelog/1172.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Interrupting a tox call (e.g. via CTRL+C) now will ensure that spawn child processes (test calls, interpreter discovery,
2+
parallel sub-instances, provisioned hosts) are correctly stopped before exiting (via the pattern of INTERRUPT - 300 ms,
3+
TERMINATE - 200 ms, KILL signals) - by :user:`gaborbernat`

docs/changelog/1203.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Setting the environment variable ``TOX_REPORTER_TIMESTAMP`` to ``1`` will enable showing for each output line its delta
2+
since the tox startup. This can be especially handy when debugging parallel runs.- by :user:`gaborbernat`

docs/changelog/998.feature.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
tox now auto-provisions itself if needed (see :ref:`auto-provision`). Plugins or minimum version of tox no longer
2-
need to be manually satisfied by the user, increasing their ease of use.
2+
need to be manually satisfied by the user, increasing their ease of use. - by :user:`gaborbernat`

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ testing =
6363
pytest-timeout >= 1.3.0, <2
6464
pytest-xdist >= 1.22.2, <2
6565
pytest-randomly >= 1.2.3, <2
66+
psutil >= 5.6.1, < 6; python_version != "3.4"
6667
docs =
6768
sphinx >= 1.8.0, < 2
6869
towncrier >= 18.5.0

src/tox/_pytestplugin.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import tox
1616
from tox import venv
1717
from tox.config import parseconfig
18+
from tox.config.parallel import ENV_VAR_KEY as PARALLEL_ENV_VAR_KEY
1819
from tox.reporter import update_default_reporter
1920
from tox.session import Session, main, setup_reporter
2021
from tox.venv import CreationConfig, VirtualEnv, getdigest
@@ -58,6 +59,40 @@ def check_cwd_not_changed_by_test():
5859
pytest.fail("test changed cwd: {!r} => {!r}".format(old, new))
5960

6061

62+
@pytest.fixture(autouse=True)
63+
def check_os_environ_stable():
64+
old = os.environ.copy()
65+
66+
to_clean = {
67+
k: os.environ.pop(k, None)
68+
for k in {PARALLEL_ENV_VAR_KEY, str("TOX_WORK_DIR"), str("PYTHONPATH")}
69+
}
70+
71+
yield
72+
73+
for key, value in to_clean.items():
74+
if value is not None:
75+
os.environ[key] = value
76+
77+
new = os.environ
78+
extra = {k: new[k] for k in set(new) - set(old)}
79+
miss = {k: old[k] for k in set(old) - set(new)}
80+
diff = {
81+
"{} = {} vs {}".format(k, old[k], new[k])
82+
for k in set(old) & set(new)
83+
if old[k] != new[k] and not k.startswith("PYTEST_")
84+
}
85+
if extra or miss or diff:
86+
msg = "test changed environ"
87+
if extra:
88+
msg += " extra {}".format(extra)
89+
if miss:
90+
msg += " miss {}".format(miss)
91+
if diff:
92+
msg += " diff {}".format(diff)
93+
pytest.fail(msg)
94+
95+
6196
@pytest.fixture(name="newconfig")
6297
def create_new_config_file(tmpdir):
6398
def create_new_config_file_(args, source=None, plugins=()):
@@ -102,6 +137,11 @@ def run_command(self):
102137
result.ret = exception.code
103138
except OSError as e:
104139
result.ret = e.errno
140+
except tox.exception.InvocationError as exception:
141+
result.ret = exception.exit_code
142+
if exception.out is not None:
143+
with open(exception.out, "rt") as file_handler:
144+
tox.reporter.verbosity0(file_handler.read())
105145
return result
106146

107147
yield run
@@ -131,13 +171,30 @@ def _read(self, out, pos):
131171

132172
@property
133173
def outlines(self):
134-
return self.out.splitlines()
174+
out = [] if self.out is None else self.out.splitlines()
175+
err = [] if self.err is None else self.err.splitlines()
176+
return err + out
135177

136178
def __repr__(self):
137179
return "RunResult(ret={}, args={}, out=\n{}\n, err=\n{})".format(
138180
self.ret, " ".join(str(i) for i in self.args), self.out, self.err
139181
)
140182

183+
def output(self):
184+
return "{}\n{}\n{}".format(self.ret, self.err, self.out)
185+
186+
def assert_success(self, is_run_test_env=True):
187+
msg = self.output()
188+
assert self.ret == 0, msg
189+
if is_run_test_env:
190+
assert any(" congratulations :)" == l for l in reversed(self.outlines)), msg
191+
192+
def assert_fail(self, is_run_test_env=True):
193+
msg = self.output()
194+
assert self.ret, msg
195+
if is_run_test_env:
196+
assert not any(" congratulations :)" == l for l in reversed(self.outlines)), msg
197+
141198

142199
class ReportExpectMock:
143200
def __init__(self):
@@ -207,6 +264,8 @@ def __init__(self, args, cwd, env, stdout, stderr, shell):
207264
self.stdout = stdout
208265
self.stderr = stderr
209266
self.shell = shell
267+
self.pid = os.getpid()
268+
self.returncode = 0
210269

211270
@staticmethod
212271
def communicate():

0 commit comments

Comments
 (0)