Skip to content

Commit c8b03ba

Browse files
committed
config: replace confusing use of parse_known_and_unknown_args in _preparse
The way our parser works, "unknown args" or only unknown *flags*. But `determine_setup` is not interested in those.
1 parent 194fe04 commit c8b03ba

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/_pytest/config/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ def _consider_importhook(self, args: Sequence[str]) -> None:
12531253
and find all the installed plugins to mark them for rewriting
12541254
by the importhook.
12551255
"""
1256-
ns, _unknown_args = self._parser.parse_known_and_unknown_args(args)
1256+
ns = self._parser.parse_known_args(args)
12571257
mode = getattr(ns, "assertmode", "plain")
12581258

12591259
disable_autoload = getattr(ns, "disable_plugin_autoload", False) or bool(
@@ -1371,13 +1371,11 @@ def _preparse(self, args: list[str], addopts: bool = True) -> None:
13711371
+ args
13721372
)
13731373

1374-
ns, unknown_args = self._parser.parse_known_and_unknown_args(
1375-
args, namespace=copy.copy(self.option)
1376-
)
1374+
ns = self._parser.parse_known_args(args, namespace=copy.copy(self.option))
13771375
rootpath, inipath, inicfg, ignored_config_files = determine_setup(
13781376
inifile=ns.inifilename,
13791377
override_ini=ns.override_ini,
1380-
args=ns.file_or_dir + unknown_args,
1378+
args=ns.file_or_dir,
13811379
rootdir_cmd_arg=ns.rootdir or None,
13821380
invocation_dir=self.invocation_params.dir,
13831381
)

src/_pytest/config/argparsing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ def parse_known_and_unknown_args(
149149
namespace: argparse.Namespace | None = None,
150150
) -> tuple[argparse.Namespace, list[str]]:
151151
"""Parse the known arguments at this point, and also return the
152-
remaining unknown arguments.
152+
remaining unknown flag arguments.
153153
154154
:returns:
155155
A tuple containing an argparse namespace object for the known
156-
arguments, and a list of the unknown arguments.
156+
arguments, and a list of unknown flag arguments.
157157
"""
158158
optparser = self._getparser()
159159
strargs = [os.fspath(x) for x in args]

0 commit comments

Comments
 (0)