Skip to content

sys.stderr replace mock with io.StringIO - #1717

Merged
lucc merged 1 commit into
pazz:masterfrom
meeuw:stderr-replace-mock-with-stringio
May 31, 2026
Merged

lucc merged 1 commit into
pazz:masterfrom
meeuw:stderr-replace-mock-with-stringio

Conversation

@meeuw

@meeuw meeuw commented May 10, 2026

Copy link
Copy Markdown
Contributor

Python 3.15 does some formatting on sys.stderr for argparse and this doesn't work with a Mock object (it tries call fileno and expects an integer).

Use io.StringIO instead, I think it's only used for supressing stderr.

Python 3.15 does some formatting on sys.stderr for argparse and this
doesn't work with a Mock object (it tries call fileno and expects an
integer).

Use io.StringIO instead, I think it's only used for supressing stderr.
@pazz

pazz commented May 31, 2026

Copy link
Copy Markdown
Owner

It looks safe to me but I'll fire up a copilot review just in case as I'm no expert. thanks for pushing this project :)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the argparse unit test helper to patch sys.stderr with a real file-like object rather than a Mock, avoiding failures in newer Python versions where argparse expects sys.stderr.fileno() to behave like a real stream.

Changes:

  • Replace mock.Mock() with io.StringIO() when patching sys.stderr during ArgumentParser.parse_args().
  • Add the required io import in the test module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lucc lucc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm

@lucc
lucc merged commit da02afb into pazz:master May 31, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants