python / python/cpython

test.test_pdb.PdbTestColorize.test_gen_colors fails when pyrepl is unavailable at runtime

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

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

tests type-bug
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 report

Bug description:
Description

test.test_pdb.PdbTestColorize.test_gen_colors can fail in the standard test suite (for example via make test) with:

Re-running test_pdb in verbose mode (matching: test_gen_colors)
test_gen_colors (test.test_pdb.PdbTestColorize.test_gen_colors) ... ERROR

======================================================================
ERROR: test_gen_colors (test.test_pdb.PdbTestColorize.test_gen_colors)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/yansendao/git/cpython-ysd/Lib/test/test_pdb.py", line 5008, in test_gen_colors
    gen_colors = p.pyrepl_input.gen_colors
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'gen_colors'

test_pdb.log

Root cause

There are two related problems:

@unittest.skipIf(not pdb._pyrepl_available()) is evaluated at import time
unittest.skipIf checks its condition when the test class is defined, not when the test runs. In regrtest worker subprocesses, sys.stdin may be a TTY at import time but is no longer suitable when the test executes, so the skip condition and runtime behavior diverge.

pdb._pyrepl_available() does not match Pdb initialization
_pyrepl_available() only consults _pyrepl.main.CAN_USE_PYREPL, which is computed once at import time. Pdb.init may still fail to create PdbPyReplInput (for example when stdin is not a TTY), silently leaving self.pyrepl_input = None.

Additionally, _pyrepl_available() always inspected sys.stdin, while Pdb uses self.stdin and self.stdout.

Steps to reproduce
time ( rm -rf build ; mkdir build ; cd build ; ../configure --prefix=$PWD/install &> configure.log ; make -j &> make.log ; make -j install &> install.log ; time make test TESTPYTHONOPTS="-s" TESTOPTS="-v -
uall,-network,-gui --junit-xml cpython.xml test_pdb" &> test_pdb.log )
CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-150545

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 với test/test_pdb.py, đặc biệt là PdbTestColorize.test_gen_colors, và lần theo điều kiện skip của nó cùng với pdb._pyrepl_available() và việc khởi tạo Pdb. Tái hiện lỗi bằng lệnh kiểm thử được nêu, sau đó xác minh rằng kiểm tra khả dụng của test khớp với hành vi runtime của Pdb và rằng test đạt khi pyrepl không khả dụ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
testing-qa
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
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
35/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.