From fe36501a1b2b0367a8c68fe0f9e59c3f8a191a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Sat, 3 Dec 2022 15:21:57 -0800 Subject: [PATCH] Support - prefix for commands exit code ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- docs/changelog/2561.bugfix.rst | 1 + src/tox/config/loader/str_convert.py | 3 +++ tests/session/cmd/test_sequential.py | 5 +++-- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/2561.bugfix.rst diff --git a/docs/changelog/2561.bugfix.rst b/docs/changelog/2561.bugfix.rst new file mode 100644 index 000000000..54c1ef350 --- /dev/null +++ b/docs/changelog/2561.bugfix.rst @@ -0,0 +1 @@ +Support in INI files for ignore exit code marker the ``-`` without a subsequent space too - by :user:`gaborbernat`. diff --git a/src/tox/config/loader/str_convert.py b/src/tox/config/loader/str_convert.py index 260f864d4..dd518e5e3 100644 --- a/src/tox/config/loader/str_convert.py +++ b/src/tox/config/loader/str_convert.py @@ -63,6 +63,9 @@ def to_command(value: str) -> Command: pos = splitter.instream.tell() except ValueError: args.append(value[pos:]) + if args[0] != "-" and args[0].startswith("-"): + args[0] = args[0][1:] + args = ["-"] + args return Command(args) @staticmethod diff --git a/tests/session/cmd/test_sequential.py b/tests/session/cmd/test_sequential.py index 66d6d7937..2aa683a37 100644 --- a/tests/session/cmd/test_sequential.py +++ b/tests/session/cmd/test_sequential.py @@ -17,9 +17,10 @@ from tox.tox_env.info import Info -def test_run_ignore_cmd_exit_code(tox_project: ToxProjectCreator) -> None: +@pytest.mark.parametrize("prefix", ["-", "- "]) +def test_run_ignore_cmd_exit_code(tox_project: ToxProjectCreator, prefix: str) -> None: cmd = [ - "- python -c 'import sys; print(\"magic fail\", file=sys.stderr); sys.exit(1)'", + f"{prefix}python -c 'import sys; print(\"magic fail\", file=sys.stderr); sys.exit(1)'", "python -c 'import sys; print(\"magic pass\", file=sys.stdout); sys.exit(0)'", ] project = tox_project({"tox.ini": f"[tox]\nno_package=true\n[testenv]\ncommands={cmd[0]}\n {cmd[1]}"})