test_shutil.test_environ_path_cwd fails when NoDefaultCurrentDirectoryInExePath is set
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 30/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- python
- Domaine
- operating-systems, testing-qa
Piste de recherche
Commencez dans Lib/test/test_shutil.py avec TestWhich.test_environ_path_cwd et TestWhichBytes.test_environ_path_cwd, puis comparez avec TestWhich.test_win_path_needs_curdir. Exécutez le module de test concerné sous Windows avec NoDefaultCurrentDirectoryInExePath défini ; c’est terminé lorsque ces tests ne dépendent plus de cette variable d’environnement et réussissent dans les deux environnements.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Merge moyen
- 1 j 9 h
- PR mergées (30 j)
- 558
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
docs pending
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
stdlib type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
-
build type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
stdlib topic-email type-feature
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
Toutes les issues de python/cpython
Issues similaires
-
fix: inaccuracy ⚠️
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
uabrc/uabrc.github.io#1255 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
ethereum-optimism/factory#64 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
duckdb/duckdb-python#627 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
-
Add link for tutorial Ouvertedocumentation
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
Qiskit/qiskit-addon-sqd#376 ·