Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Hook tracing crashes with specced Mock arguments and results

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

Maintainer thường phản hồi trong vòng 1 ngày

@RonnyPfannschmidt đang làm issue này rồi.

Từ ngày 17/10/2026.

  • #793 của @Sandeep1519-droid — đã đóng, không merge
  • #799 của @RonnyPfannschmidt — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

The reproduction calls pm.enable_tracing() and pm.trace.root.setwriter(print) on a PluginManager, and the TypeError comes from tracing code that uses isinstance on arguments and results. Start by running the reproduction script and finding the tracing formatter or result handler it reaches. Done means a specced Mock for both str and dict is logged without changing the hook result. Pull request #793 already addresses this, so review it before starting new work.

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

Mô tả

On main at 21c7e1672941a0cd9e3c555bf5e5007f1fbe3dc5 (Python 3.12.13), enabling hook tracing changes a successful hook call into a TypeError when an argument or first-result return value is a specced unittest.mock.Mock.

from unittest.mock import Mock
import pluggy

hookspec = pluggy.HookspecMarker("example")
hookimpl = pluggy.HookimplMarker("example")

class Spec:
    @hookspec(firstresult=True)
    def echo(self, value):
        """Return the value."""

class Plugin:
    @hookimpl
    def echo(self, value):
        return value

for spec in (str, dict):
    pm = pluggy.PluginManager("example")
    pm.add_hookspecs(Spec)
    pm.register(Plugin())
    value = Mock(spec=spec)
    assert pm.hook.echo(value=value) is value
    pm.trace.root.setwriter(print)
    pm.enable_tracing()
    try:
        assert pm.hook.echo(value=value) is value
    except TypeError as exc:
        print(spec.__name__, exc)

The string mock raises TypeError: object of type 'Mock' has no len() before the implementation runs. The dictionary mock raises TypeError: 'Mock' object is not iterable while tracing the result.

Mock(spec=...) reports its spec through __class__, so isinstance routes these objects into string formatting or dictionary metadata handling even though they are mocks. Tracing should log the mock without changing the hook result.

This report and a tested proposed fix were prepared with Codex.

Ngôn ngữ chính
Python
Star
1.7k
Fork
187
Merge trung bình
1 ngày 20 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

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 pytest-dev/pluggy

Tất cả issue của pytest-dev/pluggy

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.