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

Suggestion: Using capturemanager.global_and_fixture_disabled #172

Open
AbdealiLoKo opened this issue Apr 15, 2024 · 1 comment
Open

Suggestion: Using capturemanager.global_and_fixture_disabled #172

AbdealiLoKo opened this issue Apr 15, 2024 · 1 comment

Comments

@AbdealiLoKo
Copy link

AbdealiLoKo commented Apr 15, 2024

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?

@AbdealiLoKo AbdealiLoKo changed the title Suggestion: Using caplog.global_and_fixture_disabled Suggestion: Using capturemanager.global_and_fixture_disabled Apr 15, 2024
@flub
Copy link
Member

flub commented Apr 15, 2024

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?

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

No branches or pull requests

2 participants