Skip to content

Commit fc2d649

Browse files
committed
config: use argparse intermixed args parsing instead of doing it ourselves
See https://docs.python.org/3/library/argparse.html#intermixed-parsing. pytest uses the intermixed style, but implemented it manually, probably because it as only added to argparse in Python 3.7.
1 parent 8c6e01d commit fc2d649

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def parse(
111111
self.optparser = self._getparser()
112112
try_argcomplete(self.optparser)
113113
strargs = [os.fspath(x) for x in args]
114-
return self.optparser.parse_args(strargs, namespace=namespace)
114+
return self.optparser.parse_intermixed_args(strargs, namespace=namespace)
115115

116116
def _getparser(self) -> PytestArgumentParser:
117117
from _pytest._argcomplete import filescompleter
@@ -451,20 +451,6 @@ def error(self, message: str) -> NoReturn:
451451
)
452452
raise UsageError(self.format_usage() + msg)
453453

454-
# Type ignored because typeshed has a very complex type in the superclass.
455-
def parse_args( # type: ignore
456-
self,
457-
args: Sequence[str] | None = None,
458-
namespace: argparse.Namespace | None = None,
459-
) -> argparse.Namespace:
460-
"""Allow splitting of positional arguments."""
461-
parsed, unrecognized = self.parse_known_args(args, namespace)
462-
for arg in unrecognized:
463-
if arg.startswith("-"):
464-
self.error("unrecognized arguments: " + " ".join(unrecognized))
465-
getattr(parsed, FILE_OR_DIR).extend(unrecognized)
466-
return parsed
467-
468454

469455
class DropShorterLongHelpFormatter(argparse.HelpFormatter):
470456
"""Shorten help for long options that differ only in extra hyphens.

0 commit comments

Comments
 (0)