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-128438: Add EnvironmentVarGuard for test_builtin.py, test_io.py and test_locale.py #128476

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

Conversation

WolframAlph
Copy link
Contributor

@WolframAlph WolframAlph commented Jan 4, 2025

Lib/test/test_builtin.py Outdated Show resolved Hide resolved
Lib/test/test_io.py Outdated Show resolved Hide resolved
Lib/test/test_locale.py Outdated Show resolved Hide resolved
@WolframAlph WolframAlph requested a review from picnixz January 8, 2025 11:43

if 'LC_CTYPE' not in orig_env:
del os.environ['LC_CTYPE']
env['LC_CTYPE'] = 'UTF-8'
Copy link
Contributor

Choose a reason for hiding this comment

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

To mimic env.unset maybe use env.set?

Comment on lines +512 to +513
if orig_getlocale is not None:
_locale._getdefaultlocale = orig_getlocale
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just in case, keep a huge try-finally and the environment guard inside that block:

try:
	with os_helper.EnvironmentVarGuard() as env:
		...
finally:
	if orig_getlocale is not None:
		...

This would reduce the diff and ease additions in the future if we want to change the with-block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants