Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValueError: I/O operation on closed file. #1878

Closed
wants to merge 1 commit into from

Conversation

tchalupnik
Copy link

Hello Jonathan!

I found such a problem:

from prompt_toolkit import print_formatted_text
from pytest import CaptureFixture

def test_1(capsys: CaptureFixture[str]) -> None:
    print_formatted_text("TEST")


def test_2() -> None:
    print_formatted_text("TEST")

that ends up with:

py/lib/python3.11/site-packages/prompt_toolkit/shortcuts/utils.py:164: in print_formatted_text
    render()
py/lib/python3.11/site-packages/prompt_toolkit/shortcuts/utils.py:139: in render
    renderer_print_formatted_text(
py/lib/python3.11/site-packages/prompt_toolkit/renderer.py:813: in print_formatted_text
    output.flush()
py/lib/python3.11/site-packages/prompt_toolkit/output/plain_text.py:59: in flush
    flush_stdout(self.stdout, data)
py/lib/python3.11/site-packages/prompt_toolkit/output/flush_stdout.py:33: ValueError
ValueError: I/O operation on closed file.

CaptureFixture closes the output stdout so I added checks they prevent such a case

@tchalupnik
Copy link
Author

Closing as we were able to work out the better way to make Capsys pytest's feature compatible in #1880

@tchalupnik tchalupnik closed this Jun 4, 2024
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.

None yet

1 participant