diff --git a/docs/changelog/1222.bugfix.rst b/docs/changelog/1222.bugfix.rst new file mode 100644 index 000000000..4b7723f77 --- /dev/null +++ b/docs/changelog/1222.bugfix.rst @@ -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. diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py index d23f2dc8f..cca7f991a 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -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") @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 diff --git a/src/tox/action.py b/src/tox/action.py index 7adee59b3..bcc722f67 100644 --- a/src/tox/action.py +++ b/src/tox/action.py @@ -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: @@ -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 diff --git a/src/tox/venv.py b/src/tox/venv.py index a92aa711c..fd7344eaf 100644 --- a/src/tox/venv.py +++ b/src/tox/venv.py @@ -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") diff --git a/tests/unit/test_z_cmdline.py b/tests/unit/test_z_cmdline.py index b265e02e8..9b0d6e436 100644 --- a/tests/unit/test_z_cmdline.py +++ b/tests/unit/test_z_cmdline.py @@ -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")' """ @@ -730,6 +730,7 @@ def test_empty_activity_shown_verbose(initproj, cmd): [testenv] list_dependencies_command=echo commands={envpython} --version + whitelist_externals = echo """ }, )