Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/13484.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed ``known_args_namespace`` containing duplicate values for append-action arguments like ``-W`` due to re-parsing into the same namespace.
10 changes: 6 additions & 4 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ def _validate_args(self, args: list[str], via: str) -> list[str]:
self._parser.extra_info["config source"] = via
try:
self._parser.parse_known_and_unknown_args(
args, namespace=copy.copy(self.option)
args, namespace=copy.deepcopy(self.option)
)
finally:
self._parser.extra_info.pop("config source", None)
Expand Down Expand Up @@ -1500,7 +1500,7 @@ def parse(self, args: list[str], addopts: bool = True) -> None:
+ args
)

ns = self._parser.parse_known_args(args, namespace=copy.copy(self.option))
ns = self._parser.parse_known_args(args, namespace=copy.deepcopy(self.option))
rootpath, inipath, inicfg, ignored_config_files = determine_setup(
inifile=ns.inifilename,
override_ini=ns.override_ini,
Expand Down Expand Up @@ -1533,7 +1533,7 @@ def parse(self, args: list[str], addopts: bool = True) -> None:
)

self.known_args_namespace = self._parser.parse_known_args(
args, namespace=copy.copy(self.option)
args, namespace=copy.deepcopy(self.option)
)
self._checkversion()
self._consider_importhook()
Expand All @@ -1550,7 +1550,9 @@ def parse(self, args: list[str], addopts: bool = True) -> None:
# are going to be loaded.
self.pluginmanager.consider_env()

self._parser.parse_known_args(args, namespace=self.known_args_namespace)
self.known_args_namespace = self._parser.parse_known_args(
args, namespace=copy.deepcopy(self.option)
)

self._validate_plugins()
self._warn_about_skipped_plugins()
Expand Down
6 changes: 6 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2327,6 +2327,12 @@ def test_addopts_from_ini_not_concatenated(self, pytester: Pytester) -> None:
)
assert result.ret == _pytest.config.ExitCode.USAGE_ERROR

def test_append_args_not_duplicated(self, _config_for_test, _sys_snapshot) -> None:
"""Append-action args should not be duplicated after multiple parses (#13484)."""
config = _config_for_test
config.parse(["-Werror"], addopts=True)
assert config.known_args_namespace.pythonwarnings == ["error"]

def test_override_ini_does_not_contain_paths(
self, _config_for_test, _sys_snapshot
) -> None:
Expand Down