python / python/cpython

test_shutil.test_environ_path_cwd fails when NoDefaultCurrentDirectoryInExePath is set

Đang mở
#156,376 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

OS-windows tests
Ngôn ngữ chính
Python
Star
77.2k
Fork
35.9k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu trong Lib/test/test_shutil.py với TestWhich.test_environ_path_cwd và TestWhichBytes.test_environ_path_cwd, sau đó so sánh với TestWhich.test_win_path_needs_curdir. Chạy mô-đun kiểm thử bị ảnh hưởng trên Windows với NoDefaultCurrentDirectoryInExePath được thiết lập; hoàn tất khi các kiểm thử này không còn phụ thuộc vào biến môi trường đó và đều vượt qua trong cả hai môi trường.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
operating-systems, testing-qa
Loại issue
Lỗi
Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.