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

do not return the action identifier from the log #1222

Merged
merged 2 commits into from
Mar 28, 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: 2 additions & 0 deletions docs/changelog/1222.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changes to the plugin tester module (cmd no longer sets ``PYTHONPATH``), and ``action.popen`` no longer returns the
command identifier information from within the logs. No public facing changes.
31 changes: 15 additions & 16 deletions src/tox/_pytestplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import six

import tox
import tox.session
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

mark_dont_run_on_windows = pytest.mark.skipif(os.name == "nt", reason="non windows test")
Expand Down Expand Up @@ -102,7 +102,7 @@ def create_new_config_file_(args, source=None, plugins=()):
s = textwrap.dedent(source)
p = tmpdir.join("tox.ini")
p.write(s)
setup_reporter(args)
tox.session.setup_reporter(args)
with tmpdir.as_cwd():
return parseconfig(args, plugins=plugins)

Expand All @@ -117,21 +117,11 @@ def cmd(request, monkeypatch, capfd):

def run(*argv):
reset_report()
key = str("PYTHONPATH")
python_paths = (i for i in (os.getcwd(), os.getenv(key)) if i)
monkeypatch.setenv(key, os.pathsep.join(python_paths))

with RunResult(argv, capfd) as result:
prev_run_command = Session.runcommand

def run_command(self):
result.session = self
return prev_run_command(self)

monkeypatch.setattr(Session, "runcommand", run_command)
_collect_session(result)

try:
main([str(x) for x in argv])
tox.session.main([str(x) for x in argv])
assert False # this should always exist with SystemExit
except SystemExit as exception:
result.ret = exception.code
Expand All @@ -144,6 +134,15 @@ def run_command(self):
tox.reporter.verbosity0(file_handler.read())
return result

def _collect_session(result):
prev_build = tox.session.build_session

def build_session(config):
result.session = prev_build(config)
return result.session

monkeypatch.setattr(tox.session, "build_session", build_session)

yield run


Expand Down Expand Up @@ -279,7 +278,7 @@ def wait(self):
def create_mocksession(request):
config = request.getfixturevalue("newconfig")([], "")

class MockSession(Session):
class MockSession(tox.session.Session):
def __init__(self, config):
self.logging_levels(config.option.quiet_level, config.option.verbose_level)
super(MockSession, self).__init__(config, popen=self.popen)
Expand Down Expand Up @@ -561,7 +560,7 @@ def popen(cmd, **kwargs):
return ret

def build_session(config):
session = Session(config, popen=popen)
session = tox.session.Session(config, popen=popen)
res[id(session)] = Result(session)
return session

Expand Down
14 changes: 9 additions & 5 deletions src/tox/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def popen(
exit_code = process.returncode
finally:
if out_path is not None and out_path.exists():
output = out_path.read()
lines = out_path.read().split("\n")
# first three lines are the action, cwd, and cmd - remove it
output = "\n".join(lines[3:])
try:
if exit_code and not ignore_ret:
if report_fail:
Expand Down Expand Up @@ -210,11 +212,13 @@ def _get_standard_streams(self, capture_err, cmd_args_shell, redirect, returnout
if self.generate_tox_log or redirect:
out_path = self.get_log_path(self.name)
with out_path.open("wt") as stdout, out_path.open("rb") as input_file_handler:
stdout.write(
"action: {}, msg: {}\ncwd: {}\ncmd: {}\n".format(
self.name, self.msg, cwd, cmd_args_shell
)
msg = "action: {}, msg: {}\ncwd: {}\ncmd: {}\n".format(
self.name.replace("\n", " "),
self.msg.replace("\n", " "),
str(cwd).replace("\n", " "),
cmd_args_shell.replace("\n", " "),
)
stdout.write(msg)
stdout.flush()
input_file_handler.read() # read the header, so it won't be written to stdout
yield input_file_handler, out_path, stderr, stdout
Expand Down
2 changes: 1 addition & 1 deletion src/tox/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ def tox_runtest_post(venv):
def tox_runenvreport(venv, action):
# write out version dependency information
args = venv.envconfig.list_dependencies_command
output = venv._pcall(args, cwd=venv.envconfig.config.toxinidir, action=action)
output = venv._pcall(args, cwd=venv.envconfig.config.toxinidir, action=action, returnout=True)
# the output contains a mime-header, skip it
output = output.split("\n\n")[-1]
packages = output.strip().split("\n")
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_z_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ def test_result_json(cmd, initproj, example123):
deps = setuptools
commands_pre = python -c 'print("START")'
commands = python -c 'print("OK")'
- python -c 'raise SystemExit(1)'
python -c 'raise SystemExit(2)'
- python -c 'print("1"); raise SystemExit(1)'
python -c 'print("1"); raise SystemExit(2)'
python -c 'print("SHOULD NOT HAPPEN")'
commands_post = python -c 'print("END")'
"""
Expand Down Expand Up @@ -730,6 +730,7 @@ def test_empty_activity_shown_verbose(initproj, cmd):
[testenv]
list_dependencies_command=echo
commands={envpython} --version
whitelist_externals = echo
"""
},
)
Expand Down