Skip to content

Fix known_args_namespace containing duplicate append-action values#14207

Open
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700:fix-known-args-duplicate
Open

Fix known_args_namespace containing duplicate append-action values#14207
Fridayai700 wants to merge 2 commits intopytest-dev:mainfrom
Fridayai700:fix-known-args-duplicate

Conversation

@Fridayai700
Copy link

Summary

Fixes #13484

Config.known_args_namespace contains duplicate values for append-action arguments (e.g., -Werror produces pythonwarnings=['error', 'error']).

Two root causes:

  1. Third parse re-uses existing namespace: After the initial known_args_namespace is populated (line 1535), a third parse_known_args call (line 1553) re-parses into the same namespace object. For append-action arguments, this appends values that are already present.

  2. Shallow copy shares mutable state: copy.copy() on an argparse.Namespace creates a shallow copy — list attributes (like those from append actions) are shared between the original and the copy. Parsing into the copy mutates the original.

Fix: Replace the third parse's direct namespace reuse with a fresh deepcopy(self.option), and change all copy.copy(self.option) calls to copy.deepcopy(self.option).

Test plan

  • Added test_append_args_not_duplicated verifying -Werror produces exactly ['error']
  • 244/245 test_config.py tests pass (1 pre-existing subprocess failure)
  • 31/32 test_warnings.py tests pass (1 pre-existing subprocess failure)
  • 52 plugin-related tests pass

🤖 Generated with Claude Code

The third parse_known_args call re-parsed into the existing
known_args_namespace, causing append-action arguments like -W to be
duplicated. Additionally, replace copy.copy with copy.deepcopy for
all namespace copies to prevent shared mutable state between parses.

Fixes pytest-dev#13484

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config.known_args_namespace contains duplicate value

1 participant