Skip to content

Commit 91b100f

Browse files
committed
Do not allow abbreviated arguments
1 parent 4f57d40 commit 91b100f

File tree

6 files changed

+9
-4
lines changed

6 files changed

+9
-4
lines changed

changelog/1149.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Pytest no longer accepts prefixes of command-line arguments.
2+
This was previously allowed where the ``ArgumentParser`` thought it was unambigious,
3+
because this could be incorrect due to delayed parsing of options for plugins.
4+
See for example issues #1149, #3413, and #4009.

extra/get_issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def report(issues):
7474
if __name__ == "__main__":
7575
import argparse
7676

77-
parser = argparse.ArgumentParser("process bitbucket issues")
77+
parser = argparse.ArgumentParser("process bitbucket issues", allow_abbrev=False)
7878
parser.add_argument(
7979
"--refresh", action="store_true", help="invalidate cache, refresh issues"
8080
)

scripts/release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def changelog(version, write_out=False):
105105

106106
def main():
107107
init(autoreset=True)
108-
parser = argparse.ArgumentParser()
108+
parser = argparse.ArgumentParser(allow_abbrev=False)
109109
parser.add_argument("version", help="Release version")
110110
options = parser.parse_args()
111111
pre_release(options.version)

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ def __init__(self, parser, extra_info=None, prog=None):
328328
usage=parser._usage,
329329
add_help=False,
330330
formatter_class=DropShorterLongHelpFormatter,
331+
allow_abbrev=False,
331332
)
332333
# extra_info is a dict of (param -> value) to display if there's
333334
# an usage error to provide more contextual information to the user

testing/example_scripts/perf_examples/collect_stats/generate_folders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
HERE = pathlib.Path(__file__).parent
55
TEST_CONTENT = (HERE / "template_test.py").read_bytes()
66

7-
parser = argparse.ArgumentParser()
7+
parser = argparse.ArgumentParser(allow_abbrev=False)
88
parser.add_argument("numbers", nargs="*", type=int)
99

1010

testing/test_parseopt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def defaultget(option):
200200

201201
def test_drop_short_helper(self):
202202
parser = argparse.ArgumentParser(
203-
formatter_class=parseopt.DropShorterLongHelpFormatter
203+
formatter_class=parseopt.DropShorterLongHelpFormatter, allow_abbrev=False
204204
)
205205
parser.add_argument(
206206
"-t", "--twoword", "--duo", "--two-word", "--two", help="foo"

0 commit comments

Comments
 (0)