Skip to content

Suggestion: Using capturemanager.global_and_fixture_disabled #172

Open

Description

@AbdealiLoKo

I came across some odd behavior when I was debugging something related to terminal logging in pytest.
And noticed pytest-timeout was disabling capturemanager and doing it's own printing
Ref: https://github.com/pytest-dev/pytest-timeout/blob/2.3.1/pytest_timeout.py#L511

I think the better approach here may be to use global_and_fixture_disabled which is a context manager to temporarily disable capturemanager and write your own terminal outputs while it is disabled
https://github.com/pytest-dev/pytest/blob/main/src/_pytest/capture.py#L819

Any thoughts on whether this would make the logging logic simpler here?

Activity

  1. changed the title [-]Suggestion: Using caplog.global_and_fixture_disabled[/-] [+]Suggestion: Using capturemanager.global_and_fixture_disabled[/+] on Apr 15, 2024
  2. flub commented on Apr 15, 2024

    @flub
    Member

    Sounds reasonable, it's likely pytest-timemout predates that context manager. I suppose your problem was that the capturing was never re-enabled but the test run continued?

    Want to do a PR to switch to it and and make sure test coverage catches the edge cases you found?

  3. Arham-Begani commented on Oct 19, 2026

    @Arham-Begani

    I reproduced a related diagnostic gap on current main (1bbaf76) with pytest 9.1.1: a thread timeout prints its stack dump but loses stdout/stderr buffered by the test's capsys fixture. A subprocess test that prints distinct stdout/stderr markers and then times out shows neither marker in the output.

    I'll prepare a focused change using global_and_fixture_disabled, preserving fixture-buffered output before dumping diagnostics, and regression coverage for capture fixtures and disabled global capture. This work is being performed by an AI coding assistant with the account owner's authorization; no human review is claimed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions