Skip to content

Fix stdout leakage and capture#55

Open
lorey wants to merge 3 commits intomodal-labs:mainfrom
lorey:fix/stdout-capture-leak
Open

Fix stdout leakage and capture#55
lorey wants to merge 3 commits intomodal-labs:mainfrom
lorey:fix/stdout-capture-leak

Conversation

@lorey
Copy link

@lorey lorey commented Jan 1, 2026

Here's my attempt to fix #54. I've added three tests that all fail on 0.9 but work now.

  • removed the context manager that disables fixture capture
  • added a test that ensures stdout gets captured
  • added a test that ensures stdout does not leak
  • added a test that shows and checks for the related capsys bug I stumbled over when fixing

Disclosure:
I'm no expert on pytest and how this works, it's just an attempt to find a solution and provide it with the help of Claude

lorey added 2 commits January 1, 2026 18:03
These tests verify that print() output from markdown code blocks is
properly captured by pytest rather than leaking to stdout.
The MarkdownInlinePythonItem.runtest() method was using
capman.global_and_fixture_disabled(), which disables pytest's capture.
The comment claimed it "ensures capture works" but the API does the
opposite. This caused all print() output from markdown code examples
to leak to stdout during test runs.

Pytest captures stdout by default, so no special handling is needed.
@lorey lorey changed the title Fix/stdout capture leak Fix stdout leakage and capture Jan 1, 2026
Verifies that pytest's capsys fixture works correctly in markdown
code blocks. This test fails on the buggy code because
global_and_fixture_disabled() also disabled fixture-level capture.
@freider
Copy link
Collaborator

freider commented Jan 30, 2026

Thanks! I don't remember the exact circumstances for why the capture disabling was added, but I think it might have been the opposite issue - something along the lines of output not getting printed out when using the -s pytest option (which should be passing through the output) or having failing tests - have you confirmed that works after making this change?

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.

stdout from markdown leaks to terminal

2 participants