Print checking swallows writes to explicit output streams

Open
#96 1 comment 0 reactions 0 assignees View on GitHub

@vinsymoyya is already working on this.

Since Nov 13, 2026.

  • #97 by @vinsymoyya — open

Assessment

Difficulty
3/5
Estimated time
Half a day
Newbie friendliness
22/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

Start with the print interceptor that EvalExample.run_print_check() uses, and check how it handles the file keyword argument. Linked pull request #97 already targets this, so review its diff and discussion before writing anything. Done means the StringIO example from the issue passes, the stdout controls still pass, and the existing test suite stays green.

Written by the indexing model from the issue text.

Description

Reproduced on main at df945f7043cb8c456359b01700f3d664d30fbe44.

The print interceptor captures every call, including print(..., file=buffer). The destination never receives the text, so otherwise valid examples that use StringIO or another explicit text stream can fail their assertions.

from io import StringIO
buffer = StringIO()
print('hello', 'world', sep=':', end='!', file=buffer, flush=True)
assert buffer.getvalue() == 'hello:world!'

Run this through EvalExample.run_print_check(). The assertion fails because the buffer is empty.

Expected: checking/updating output preserves valid Python print semantics and produces compilable source.

Contract: https://docs.python.org/3/library/functions.html#print

The explicit-stream regression fails before the fix, while two stdout controls pass. All three pass afterward. The independently checked full local suite passes 84 tests with one expected failure and the known Windows object-address case deselected.

Relevant current and closed PR patches and issue discussions were checked; this does not duplicate the existing object-address, set-output, control-flow, metadata or indentation fixes.

Dominant language
Python
Stars
181
Forks
31
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydantic/pytest-examples

All issues in pydantic/pytest-examples

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.