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

gh-128377: Fix test_cmd_line.test_non_interactive_output_buffering fail with PYTHONUNBUFFERED=1 #128378

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

WolframAlph
Copy link
Contributor

@WolframAlph WolframAlph commented Dec 31, 2024

@WolframAlph WolframAlph changed the title gh-128377: Fix test_cmd_line fail with PYTHONUNBUFFERED=1 gh-128377: Fix test_cmd_line.test_non_interactive_output_buffering fail with PYTHONUNBUFFERED=1 Dec 31, 2024
Lib/test/test_cmd_line.py Outdated Show resolved Hide resolved
Lib/test/test_cmd_line.py Outdated Show resolved Hide resolved
Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use os_helper.EnvironmentVarGuard() instead of manually messing with os.environ.

@picnixz
Copy link
Contributor

picnixz commented Dec 31, 2024

We should use os_helper.EnvironmentVarGuard() instead of manually messing with os.environ.

Thanks for this one. I didn't know whether we had something like that somewhere but you found what I wanted to emulate with mock.patch.dict.

@WolframAlph
Copy link
Contributor Author

@ZeroIntensity thanks for pointing to that

Copy link
Contributor

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (for reviewers, it's easier to hide whitespace changes).

Copy link
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but feels kind of hacky. Why not just unittest.skipIf(os.environ.get("PYTHONUNBUFFERED"))? (Also I'd like to hear @picnixz's preference.)

@picnixz
Copy link
Contributor

picnixz commented Jan 1, 2025

Now that you're raising this issue, I'd actually prefer skipping it. If the test is broken when you use PYTHONUNBUFFERED=1 (broken because of unsatisfied pre-requirements, namely it could never work with this configuration), then it's probably fine to just skip it. Changing locally the environment is like saying "hey, you run the test suite with this configuration, but this test is not compatible with that configuration, so we'll temporarily change your configuration so that the test can run".

So yes, let's just skip the test.

Lib/test/test_cmd_line.py Outdated Show resolved Hide resolved
@WolframAlph
Copy link
Contributor Author

Sorry linter failed, did not have pre-commit hooks installed. Will fix asap

@WolframAlph WolframAlph requested a review from picnixz January 11, 2025 08:15
Lib/test/test_cmd_line.py Outdated Show resolved Hide resolved
@picnixz
Copy link
Contributor

picnixz commented Jan 11, 2025

Thanks. I'll merge this one tomorrow (I'll write a nice commit message).

@ZeroIntensity
Copy link
Member

Having fun with your commit privileges already I see 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants