cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-75729: Fix os.spawn tests not handling spaces on Windows

Open CAM-Gerlach opened this issue 3 years ago • 5 comments

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.

  • Issue: gh-75729

CAM-Gerlach avatar Nov 06 '22 07:11 CAM-Gerlach

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.

CAM-Gerlach avatar Nov 06 '22 07:11 CAM-Gerlach

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

JelleZijlstra avatar Nov 06 '22 14:11 JelleZijlstra

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.

CAM-Gerlach avatar Nov 07 '22 00:11 CAM-Gerlach

Does os.exec tests need a similar fix?

serhiy-storchaka avatar Nov 08 '22 06:11 serhiy-storchaka

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.

CAM-Gerlach avatar Nov 08 '22 07:11 CAM-Gerlach

Is this ready to merge?

hugovk avatar Apr 07 '23 15:04 hugovk

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.

CAM-Gerlach avatar Apr 08 '23 05:04 CAM-Gerlach

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

miss-islington avatar Apr 08 '23 07:04 miss-islington

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

bedevere-bot avatar Apr 08 '23 07:04 bedevere-bot