Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various fixes related to sub-process handling #1186

Merged
merged 9 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ variables:
CI_NAME: Azure Pipelines
CI_BUILD_ID: $(Build.BuildId)
CI_BUILD_URL: "https://toxdev.visualstudio.com/tox/_build/results?buildId=$(Build.BuildId)"
PYTEST_ADDOPTS: "-vv -ra --showlocals"
PYTEST_ADDOPTS: "-v -v -ra --showlocals"
GIT_BRANCH: $[ coalesce(variables['System.PullRequest.SourceBranch'], variables['Build.SourceBranchName'], 'not-found') ]
GIT_COMMIT_SHA: $[ coalesce(variables['System.PullRequest.SourceCommitId'], variables['Build.SourceVersion'], 'not-found') ]

Expand Down
1 change: 1 addition & 0 deletions docs/changelog/1137.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug of children process calls logs clashing (log already exists) - by :user:`gaborbernat`
3 changes: 2 additions & 1 deletion docs/changelog/1139.feature.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tox will inject the ``TOX_PARALLEL_ENV`` environment variable, set to the current running tox environment name, only when running in parallel mode.
tox will inject the ``TOX_PARALLEL_ENV`` environment variable, set to the current running tox environment name,
only when running in parallel mode. - by :user:`gaborbernat`
1 change: 1 addition & 0 deletions docs/changelog/1143.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parallel children now save their output to a disk logfile - by :user:`gaborbernat`
2 changes: 2 additions & 0 deletions docs/changelog/1150.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Interpreter discovery and virtualenv creation process calls that failed will now print out on the screen their output
(via the logfile we automatically save) - by :user:`gaborbernat`
1 change: 1 addition & 0 deletions docs/changelog/1159.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parallel children now are added to ``--result-json`` - by :user:`gaborbernat`
2 changes: 1 addition & 1 deletion docs/changelog/1163.doc.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add a ``poetry`` examples to packaging.
Add a ``poetry`` examples to packaging - by :user:`gaborbernat`
3 changes: 3 additions & 0 deletions docs/changelog/1172.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Interrupting a tox call (e.g. via CTRL+C) now will ensure that spawn child processes (test calls, interpreter discovery,
parallel sub-instances, provisioned hosts) are correctly stopped before exiting (via the pattern of INTERRUPT - 300 ms,
TERMINATE - 200 ms, KILL signals) - by :user:`gaborbernat`
2 changes: 2 additions & 0 deletions docs/changelog/1203.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Setting the environment variable ``TOX_REPORTER_TIMESTAMP`` to ``1`` will enable showing for each output line its delta
since the tox startup. This can be especially handy when debugging parallel runs.- by :user:`gaborbernat`
2 changes: 1 addition & 1 deletion docs/changelog/998.feature.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tox now auto-provisions itself if needed (see :ref:`auto-provision`). Plugins or minimum version of tox no longer
need to be manually satisfied by the user, increasing their ease of use.
need to be manually satisfied by the user, increasing their ease of use. - by :user:`gaborbernat`
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ testing =
pytest-timeout >= 1.3.0, <2
pytest-xdist >= 1.22.2, <2
pytest-randomly >= 1.2.3, <2
psutil >= 5.6.1, < 6; python_version != "3.4"
docs =
sphinx >= 1.8.0, < 2
towncrier >= 18.5.0
Expand Down
61 changes: 60 additions & 1 deletion src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import tox
from tox import venv
from tox.config import parseconfig
from tox.config.parallel import ENV_VAR_KEY as PARALLEL_ENV_VAR_KEY
from tox.reporter import update_default_reporter
from tox.session import Session, main, setup_reporter
from tox.venv import CreationConfig, VirtualEnv, getdigest
Expand Down Expand Up @@ -58,6 +59,40 @@ def check_cwd_not_changed_by_test():
pytest.fail("test changed cwd: {!r} => {!r}".format(old, new))


@pytest.fixture(autouse=True)
def check_os_environ_stable():
old = os.environ.copy()

to_clean = {
k: os.environ.pop(k, None)
for k in {PARALLEL_ENV_VAR_KEY, str("TOX_WORK_DIR"), str("PYTHONPATH")}
}

yield

for key, value in to_clean.items():
if value is not None:
os.environ[key] = value

new = os.environ
extra = {k: new[k] for k in set(new) - set(old)}
miss = {k: old[k] for k in set(old) - set(new)}
diff = {
"{} = {} vs {}".format(k, old[k], new[k])
for k in set(old) & set(new)
if old[k] != new[k] and not k.startswith("PYTEST_")
}
if extra or miss or diff:
msg = "test changed environ"
if extra:
msg += " extra {}".format(extra)
if miss:
msg += " miss {}".format(miss)
if diff:
msg += " diff {}".format(diff)
pytest.fail(msg)


@pytest.fixture(name="newconfig")
def create_new_config_file(tmpdir):
def create_new_config_file_(args, source=None, plugins=()):
Expand Down Expand Up @@ -102,6 +137,11 @@ def run_command(self):
result.ret = exception.code
except OSError as e:
result.ret = e.errno
except tox.exception.InvocationError as exception:
result.ret = exception.exit_code
if exception.out is not None:
with open(exception.out, "rt") as file_handler:
tox.reporter.verbosity0(file_handler.read())
return result

yield run
Expand Down Expand Up @@ -131,13 +171,30 @@ def _read(self, out, pos):

@property
def outlines(self):
return self.out.splitlines()
out = [] if self.out is None else self.out.splitlines()
err = [] if self.err is None else self.err.splitlines()
return err + out

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

def output(self):
return "{}\n{}\n{}".format(self.ret, self.err, self.out)

def assert_success(self, is_run_test_env=True):
msg = self.output()
assert self.ret == 0, msg
if is_run_test_env:
assert any(" congratulations :)" == l for l in reversed(self.outlines)), msg

def assert_fail(self, is_run_test_env=True):
msg = self.output()
assert self.ret, msg
if is_run_test_env:
assert not any(" congratulations :)" == l for l in reversed(self.outlines)), msg


class ReportExpectMock:
def __init__(self):
Expand Down Expand Up @@ -207,6 +264,8 @@ def __init__(self, args, cwd, env, stdout, stderr, shell):
self.stdout = stdout
self.stderr = stderr
self.shell = shell
self.pid = os.getpid()
self.returncode = 0

@staticmethod
def communicate():
Expand Down
Loading