Skip to content

Conversation

@bluetech
Copy link
Member

These are some small cleanups to the config/argparsing code. Nothing big but maybe making the code a bit easier to follow.

I explain each change in its own commit.

It doesn't help understanding much and doesn't deal with only ini
(config). So inline it into `_preparse`.
Set to `None` instead of using `hasattr`.
Initially wanted to rename it to `MyArgumentParser` to make it clearer
it's an `argparse.ArgumentParser`. But "My" looks funny, so change to
`Pytest` similar to `PytestPluginManager`.
It only makes the code harder to understand in my opinion.

Also remove the manual `setattr(option, name, value)` which are unneeded
because `parse` already updates the `Namespace`.
This way it works for any error, which seems like better separation of
concerns.
Let's use a single mechanism. The error is now shown in its own line but
that's fine.
…elves

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.
@bluetech bluetech added the skip news used on prs to opt out of the changelog requirement label Oct 29, 2025
Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@bluetech
Copy link
Member Author

Thanks for the review @nicoddemus. I snuck in another commit, which just removes some unused global variable.

@bluetech bluetech merged commit 5eaad82 into pytest-dev:main Oct 30, 2025
33 checks passed
@bluetech bluetech deleted the config-cleanups branch October 30, 2025 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants