test_shutil.test_environ_path_cwd fails when NoDefaultCurrentDirectoryInExePath is set
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug description:
test.test_shutil.TestWhich.test_environ_path_cwd and
test.test_shutil.TestWhichBytes.test_environ_path_cwd fail on Windows when the
environment variable NoDefaultCurrentDirectoryInExePath is set in the
environment the test suite runs in:
FAIL: test_environ_path_cwd (test.test_shutil.TestWhich.test_environ_path_cwd)
----------------------------------------------------------------------
AssertionError: '@test_21832_tmpæ.Exe' != '.\@test_21832_tmpæ.Exe'
- @test_21832_tmpæ.Exe
+ .\@test_21832_tmpæ.Exe
The test asserts that shutil.which() finds the file in the current directory,
expecting a .\-prefixed result on Windows. However, shutil.which() only
inserts the current directory into the search path when
_win_path_needs_curdir() returns true (Lib/shutil.py), and that delegates to
_winapi.NeedCurrentDirectoryForExePath(). The underlying
NeedCurrentDirectoryForExePathW() API consults
NoDefaultCurrentDirectoryInExePath, so when that variable is present the
current directory is not searched and the assertion fails.
The test does use os_helper.EnvironmentVarGuard, but only to set PATH; it
does not neutralise NoDefaultCurrentDirectoryInExePath, so an ambient value
leaks into the test. TestWhich.test_win_path_needs_curdir in the same file
already accounts for this mechanism by patching
_winapi.NeedCurrentDirectoryForExePath.
Reproducer on Windows:
set NoDefaultCurrentDirectoryInExePath=1
python -m test test_shutil
Unsetting the variable inside the existing EnvironmentVarGuard makes the test
independent of the ambient environment. I have a fix and will open a PR.
CPython versions tested on:
3.16 (main, commit 04242c027fe)
Operating systems tested on:
Windows 11
Linked PRs
- gh-156377
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in Lib/test/test_shutil.py con TestWhich.test_environ_path_cwd e TestWhichBytes.test_environ_path_cwd, quindi confronta TestWhich.test_win_path_needs_curdir. Esegui il modulo di test interessato su Windows con NoDefaultCurrentDirectoryInExePath impostata; il lavoro è completato quando questi test non dipendono più da quella variabile d’ambiente e passano in entrambi gli ambienti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- operating-systems, testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 30/100