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-75729: Fix os.spawn tests not handling spaces on Windows #99150

Merged
merged 4 commits into from
Apr 8, 2023

Conversation

CAM-Gerlach
Copy link
Member

@CAM-Gerlach CAM-Gerlach commented Nov 6, 2022

As originally reported in #75729 and confirmed to still be reproducible on the latest Python 3.12, the various os.spawn* tests are broken on Windows if the current working directory contains any spaces in its path (e.g. due to spaces in the username), as on Windows the arguments are simply concatenated and not quoted. This PR fixes the immediate issue with the tests by quoting the arguments in question on Windows.

@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Nov 6, 2022

Should this have a NEWS entry? I see some PRs that only change the tests have them, but many (perhaps most?) I spot-checked don't.

@JelleZijlstra
Copy link
Member

I think a NEWS entry is helpful here because this could affect redistributors or users who are trying to run the tests locally.

@CAM-Gerlach CAM-Gerlach force-pushed the fix-spawn-tests-space-in-path branch from a1c2023 to 2362e81 Compare November 7, 2022 00:54
@CAM-Gerlach
Copy link
Member Author

CAM-Gerlach commented Nov 7, 2022

Thanks, I added one, but it seems there's something funny going on with GitHub, as when I pushed it failed multiple times with a strange error, even after I reset and re-committed:

remote: fatal error in commit_refs
To github.com:CAM-Gerlach/cpython.git
 ! [remote rejected]         fix-spawn-tests-space-in-path -> fix-spawn-tests-space-in-path (failure)
error: failed to push some refs to 'github.com:CAM-Gerlach/cpython.git'

I then force pushed and my fork updated, but nothing happened here for several minutes. Finally I rebased and force-pushed again, and it appears to have updated here, but the GHA webhooks still aren't firing yet.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@serhiy-storchaka
Copy link
Member

Does os.exec tests need a similar fix?

@CAM-Gerlach
Copy link
Member Author

Good question, and at least as far as the scope of this PR, the os.spawn* tests are the only ones affected in the os module (there are a couple unrelated tests affected in other modules, which I will be opening separate issues/PRs for), when tested with both the interpreter path, the working dir path and the temp dir path all containing spaces (given they are all under a user directory containing such).

However, the os.exec* functions on Windows do have the same issue as the os.spawn* functions, a fact I will note on the corresponding issue—but their tests don't, because as far as I could find, there apparently are no tests of os.exec* where this issue would be triggered, since the only tests are for empty, invalid, etc. arguments that return with an exception before the bad behavior would be triggered at the OS level. I'm guessing this is because if os.exec* actually executed successfully, this would naturally break the tests, since the testing process would get replaced with whatever is launched.

@hugovk hugovk removed the needs backport to 3.10 only security fixes label Apr 7, 2023
@hugovk
Copy link
Member

hugovk commented Apr 7, 2023

Is this ready to merge?

@CAM-Gerlach
Copy link
Member Author

It should be as far as I'm aware, yeah—there are some other issues that need another round of discussion, but we can at least fix the tests for now.

@hugovk hugovk merged commit a34c796 into python:main Apr 8, 2023
@miss-islington
Copy link
Contributor

Thanks @CAM-Gerlach for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-103366 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Apr 8, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2023
…thonGH-99150)

* Quote paths in os.spawn tests on Windows so they work with spaces

* Add NEWS entry for os spawn test fix

* Fix code style to avoid double negative in os.spawn tests

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

---------

(cherry picked from commit a34c796)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
miss-islington added a commit that referenced this pull request Apr 8, 2023
* Quote paths in os.spawn tests on Windows so they work with spaces

* Add NEWS entry for os spawn test fix

* Fix code style to avoid double negative in os.spawn tests

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

---------

(cherry picked from commit a34c796)

Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
warsaw pushed a commit to warsaw/cpython that referenced this pull request Apr 11, 2023
…thon#99150)

* Quote paths in os.spawn tests on Windows so they work with spaces

* Add NEWS entry for os spawn test fix

* Fix code style to avoid double negative in os.spawn tests

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>

---------

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-windows tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants