python / python/cpython

test_shutil.test_environ_path_cwd fails when NoDefaultCurrentDirectoryInExePath is set

Aberta
#156,376 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

OS-windows tests
Linguagem predominante
Python
Estrelas
77.2k
Forks
35.9k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece em Lib/test/test_shutil.py com TestWhich.test_environ_path_cwd e TestWhichBytes.test_environ_path_cwd; depois, compare com TestWhich.test_win_path_needs_curdir. Execute o módulo de testes afetado no Windows com NoDefaultCurrentDirectoryInExePath definido; considera-se concluído quando esses testes não dependerem mais dessa variável de ambiente e passarem em ambos os ambientes.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
operating-systems, testing-qa
Tipo de issue
Bug
Dificuldade
2/5
Tempo estimado
1-3 horas
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.