-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent argument exit code when argparse exit with its own e…
…rror code (#7931) (#7943) Returning 2 here is confusing as it doesn't match the documentation: https://pylint.pycqa.org/en/latest/user_guide/usage/run.html#exit-codes * pylint: use exit code 32 when invalid arguments are passed * pylint: add failing test when ambiguous abbreviated parameters are set in a config file This is confusing behaviour. The output is: ``` usage: pylint [options] pylint: error: ambiguous option: --no could match --notes, --notes-rgx, --no-docstring-rgx ``` The exit code is 2 which doesn't match the documentation: https://pylint.pycqa.org/en/latest/user_guide/usage/run.html#exit-codes * pylint: use exit code 32 when ambiguous abbreviated parameters are set in a config file Co-authored-by: Pierre Sassoulas <[email protected]> (cherry picked from commit 62232b3) Co-authored-by: David Lawson <[email protected]>
- Loading branch information
1 parent
494e514
commit dca3940
Showing
5 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
When pylint exit due to bad arguments being provided the exit code will now be the expected ``32``. | ||
|
||
Refs #7931 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html | ||
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE | ||
# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt | ||
|
||
from pathlib import Path | ||
|
||
import pytest | ||
from _pytest.capture import CaptureFixture | ||
|
||
from pylint import run_pylint | ||
|
||
|
||
def test_run_pylint_with_invalid_argument(capsys: CaptureFixture[str]) -> None: | ||
"""Check that appropriate exit code is used with invalid argument.""" | ||
with pytest.raises(SystemExit) as ex: | ||
run_pylint(["--never-use-this"]) | ||
captured = capsys.readouterr() | ||
assert captured.err.startswith("usage: pylint [options]") | ||
assert ex.value.code == 32 | ||
|
||
|
||
def test_run_pylint_with_invalid_argument_in_config( | ||
capsys: CaptureFixture[str], tmp_path: Path | ||
) -> None: | ||
"""Check that appropriate exit code is used with an ambiguous | ||
argument in a config file. | ||
""" | ||
test_file = tmp_path / "testpylintrc" | ||
with open(test_file, "w", encoding="utf-8") as f: | ||
f.write("[MASTER]\nno=") | ||
|
||
with pytest.raises(SystemExit) as ex: | ||
run_pylint(["--rcfile", f"{test_file}"]) | ||
captured = capsys.readouterr() | ||
assert captured.err.startswith("usage: pylint [options]") | ||
assert ex.value.code == 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters