pytest-dev / pytest-dev/pytest

calling capture.resume_global_capture() changes the used terminal width

Open
#13,322 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

plugin: capture type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

I have to suspend the global capture, because I ask the user for some user input in my pytest plugin.
But this leads to a changed terminal width.

conftest.py

import pytest
import shutil


@pytest.hookimpl(trylast=True)
def pytest_sessionfinish(session):
    capture = session.config.pluginmanager.getplugin("capturemanager")
    capture.suspend_global_capture(in_=True)

    # some code to read user input

    print(shutil.get_terminal_size())
    capture.resume_global_capture()
    print(shutil.get_terminal_size())

Image

The === in the no tests ran line are shorter than above and the result of get_terminal_size changed.

pytest: 8.3.5
os: Debian

I performed this test in a directory that only contained the specified file conftest.py.

Contributor guide

Open the contributing guide

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.

Research direction

Start with the conftest.py reproduction and compare shutil.get_terminal_size() before and after capture.suspend_global_capture(in_=True) and capture.resume_global_capture(). Trace the capture manager entry points involved and add or update a regression test demonstrating the terminal width remains consistent after resuming global capture.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.