Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFire

Đang mở Phù hợp với người mới
#693 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.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu trong fire/main_test.py tại MainModuleTest.testArgPassing và MainModuleFileTest.setUp/testFileNameFire, sau đó chạy bộ kiểm thử Windows bằng pytest. Kiểm tra ngữ cảnh hiện có của PR #679 về lỗi regex và xác minh rằng các tệp tạm thời có thể được mở lại trong quá trình import. Hoàn tất khi cả 261 kiểm thử đều vượt qua trên Windows và POSIX.

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

Mô tả

On a fresh clone on Windows, the test suite fails 2 of 261 tests, both in fire/main_test.py and both Windows-specific. CI currently runs macos-latest + ubuntu-latest only, so neither can be caught there.

FAILED fire/main_test.py::MainModuleTest::testArgPassing - re.PatternError: bad escape \p at position 5
FAILED fire/main_test.py::MainModuleFileTest::testFileNameFire - PermissionError: [Errno 13] Permission denied: 'C:\\...\\tmponwjvj2u.py'
2 failed, 259 passed in 6.30s

Environment: Windows 11, Python 3.13.13, pip install -e . pytest hypothesis, clone at current master.

1. testArgPassing — unescaped path in a regex. assertOutputMatches treats its argument as a regex, and the test interpolates os.path.join('part1', 'part2', 'part3') unescaped. On Windows that's part1\part2\part3, and \p has been a hard error (re.PatternError) since Python 3.12. POSIX never sees it because / needs no escaping. The open PR #679 fixes exactly this with re.escape(); applying its change locally takes the suite to 1 failed / 260 passed, so it would be lovely to see it merged.

2. testFileNameFireNamedTemporaryFile can't be reopened while open on Windows. MainModuleFileTest.setUp keeps the temp .py file open, and fire.__main__.import_from_file_pathexec_module then opens it a second time for import. That second open is the documented Windows limitation of NamedTemporaryFile ("the name cannot be used to open the file a second time while it is still open"), and it surfaces as PermissionError inside the import machinery. This is test-harness-only: python -m fire somefile.py itself works fine on Windows.

Fix I verified locally for (2) — with it (plus #679's change), the whole suite passes on this machine, 261 passed in 1.65s, and it stays green on POSIX semantics:

   def setUp(self):
     super().setUp()
-    self.file = tempfile.NamedTemporaryFile(suffix='.py')  # pylint: disable=consider-using-with
+    self.file = tempfile.NamedTemporaryFile(suffix='.py', delete=False)  # pylint: disable=consider-using-with
     self.file.write(b'class Foo:\n  def double(self, n):\n    return 2 * n\n')
-    self.file.flush()
+    self.file.close()
+    self.addCleanup(os.unlink, self.file.name)

-    self.file2 = tempfile.NamedTemporaryFile()  # pylint: disable=consider-using-with
+    self.file2 = tempfile.NamedTemporaryFile(delete=False)  # pylint: disable=consider-using-with
+    self.file2.close()
+    self.addCleanup(os.unlink, self.file2.name)

(delete_on_close=False would be tidier but is 3.12+, and setup.py still advertises 3.7 support.)

I'm reporting this as an issue rather than sending the patch because I haven't signed the Google CLA yet. Happy for anyone — including the author of #679 — to fold the diff above into a PR. Also happy to follow up with a windows-latest line for the CI matrix discussion if that's of interest, though I understand that's a bigger decision than these two fixes.

Ngôn ngữ chính
Python
Star
28.2k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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.

Issue khác của google/python-fire

Tất cả issue của google/python-fire

Issue tương tự

Thêm issue về Python

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.