Skip to content

Conversation

moreati
Copy link
Contributor

@moreati moreati commented Sep 14, 2024

During review of #116131 the necessity of introducing test.support.os_helper.save_cwd() and test.support.os_helper.save_mode() has been rightfully queried. I have verified save_mode() is necessary, as described in #116131 (comment).

This PR is intended to run a variation of PR #116131 without save_cwd() through the CPython CI. If this variation passes, then save_cwd() is unnecessary. If a failure of test.test_import_lib.import_.test_permission_error_cwd() is introduced, then it will inform the reviews, and serve as a reference for updating comments/docstrings.


📚 Documentation preview 📚: https://cpython-previews--124091.org.readthedocs.build/

moreati and others added 3 commits September 13, 2024 12:03
On macOS `getcwd(3)` can return EACCES if a path component isn't readable,
resulting in PermissionError. `PathFinder.find_spec()` now catches these and
ignores them - the same treatment as a missing/deleted cwd.

Introduces 2 new `test.support.os_helper` context managers

- `save_mode(path, ...)` - restores the mode of a path on exit
- `save_cwd(...)` - restores the current directory on exit

Unlike `change_cwd(path)` (which always performs a `chdir(path)`),
`save_cwd()` allows the code inside the `with` block to control this. The new
context manager just restores the original working directory afterward.

This is allows finer control of exception handling and robust environment
restoration across platforms in `FinderTests.test_permission_error_cwd()`.
Apply suggestions from code review

Co-authored-by: Brett Cannon <[email protected]>
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

Successfully merging this pull request may close these issues.

1 participant