From 91b100f3feac877afec3711961d393d0c8d15f9a Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 22 Jun 2019 21:11:12 +1000 Subject: [PATCH] Do not allow abbreviated arguments --- changelog/1149.feature.rst | 4 ++++ extra/get_issues.py | 2 +- scripts/release.py | 2 +- src/_pytest/config/argparsing.py | 1 + .../perf_examples/collect_stats/generate_folders.py | 2 +- testing/test_parseopt.py | 2 +- 6 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changelog/1149.feature.rst diff --git a/changelog/1149.feature.rst b/changelog/1149.feature.rst new file mode 100644 index 00000000000..fec257d5348 --- /dev/null +++ b/changelog/1149.feature.rst @@ -0,0 +1,4 @@ +Pytest no longer accepts prefixes of command-line arguments. +This was previously allowed where the ``ArgumentParser`` thought it was unambigious, +because this could be incorrect due to delayed parsing of options for plugins. +See for example issues #1149, #3413, and #4009. diff --git a/extra/get_issues.py b/extra/get_issues.py index 9407aeded7d..ae99c9aa60e 100644 --- a/extra/get_issues.py +++ b/extra/get_issues.py @@ -74,7 +74,7 @@ def report(issues): if __name__ == "__main__": import argparse - parser = argparse.ArgumentParser("process bitbucket issues") + parser = argparse.ArgumentParser("process bitbucket issues", allow_abbrev=False) parser.add_argument( "--refresh", action="store_true", help="invalidate cache, refresh issues" ) diff --git a/scripts/release.py b/scripts/release.py index 5009df359e6..d2a51e25a4f 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -105,7 +105,7 @@ def changelog(version, write_out=False): def main(): init(autoreset=True) - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser(allow_abbrev=False) parser.add_argument("version", help="Release version") options = parser.parse_args() pre_release(options.version) diff --git a/src/_pytest/config/argparsing.py b/src/_pytest/config/argparsing.py index fb36c798526..b86fc756922 100644 --- a/src/_pytest/config/argparsing.py +++ b/src/_pytest/config/argparsing.py @@ -328,6 +328,7 @@ def __init__(self, parser, extra_info=None, prog=None): usage=parser._usage, add_help=False, formatter_class=DropShorterLongHelpFormatter, + allow_abbrev=False, ) # extra_info is a dict of (param -> value) to display if there's # an usage error to provide more contextual information to the user diff --git a/testing/example_scripts/perf_examples/collect_stats/generate_folders.py b/testing/example_scripts/perf_examples/collect_stats/generate_folders.py index ff1eaf7d6bb..d2c1a30b2bb 100644 --- a/testing/example_scripts/perf_examples/collect_stats/generate_folders.py +++ b/testing/example_scripts/perf_examples/collect_stats/generate_folders.py @@ -4,7 +4,7 @@ HERE = pathlib.Path(__file__).parent TEST_CONTENT = (HERE / "template_test.py").read_bytes() -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser(allow_abbrev=False) parser.add_argument("numbers", nargs="*", type=int) diff --git a/testing/test_parseopt.py b/testing/test_parseopt.py index 7c581cce164..9bd686d8f69 100644 --- a/testing/test_parseopt.py +++ b/testing/test_parseopt.py @@ -200,7 +200,7 @@ def defaultget(option): def test_drop_short_helper(self): parser = argparse.ArgumentParser( - formatter_class=parseopt.DropShorterLongHelpFormatter + formatter_class=parseopt.DropShorterLongHelpFormatter, allow_abbrev=False ) parser.add_argument( "-t", "--twoword", "--duo", "--two-word", "--two", help="foo"