diff --git a/doc/whatsnew/fragments/9343.bugfix b/doc/whatsnew/fragments/9343.bugfix index bdae77d6ff..0a3a620809 100644 --- a/doc/whatsnew/fragments/9343.bugfix +++ b/doc/whatsnew/fragments/9343.bugfix @@ -1,3 +1,4 @@ -Fixed a crash in ``symilar`` when the ``-d`` option was not properly recognized. +Fixed a crash in ``symilar`` when the ``-d`` or ``-i`` short option were not properly recognized. +It's still impossible to do ``-d=1`` (you must do ``-d 1``). Closes #9343 diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 40eba0bb15..ee1b608433 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -907,7 +907,7 @@ def Run(argv: Sequence[str] | None = None) -> NoReturn: if argv is None: argv = sys.argv[1:] - s_opts = "hdi" + s_opts = "hd:i:" l_opts = [ "help", "duplicates=", diff --git a/tests/checkers/unittest_similar.py b/tests/checkers/unittest_similar.py index 30279bf966..91a9e5e545 100644 --- a/tests/checkers/unittest_similar.py +++ b/tests/checkers/unittest_similar.py @@ -499,14 +499,14 @@ def test_set_duplicate_lines_to_zero() -> None: assert output.getvalue() == "" -@pytest.mark.parametrize("v", ["d", "i"]) +@pytest.mark.parametrize("v", ["d"]) def test_bad_equal_short_form_option(v: str) -> None: """Regression test for https://github.com/pylint-dev/pylint/issues/9343""" output = StringIO() with redirect_stdout(output), pytest.raises(SystemExit) as ex: similar.Run([f"-{v}=0", SIMILAR1, SIMILAR2]) assert ex.value.code == 2 - assert "option -= not recognized" in output.getvalue() + assert "invalid literal for int() with base 10: '=0'" in output.getvalue() @pytest.mark.parametrize("v", ["i", "d"]) @@ -515,8 +515,8 @@ def test_space_short_form_option(v: str) -> None: output = StringIO() with redirect_stdout(output), pytest.raises(SystemExit) as ex: similar.Run([f"-{v} 2", SIMILAR1, SIMILAR2]) - assert ex.value.code == 2 - assert "option - not recognized" in output.getvalue() + assert ex.value.code == 0 + assert "similar lines in" in output.getvalue() def test_bad_short_form_option() -> None: