Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Hook tracing crashes with specced Mock arguments and results

未关闭
#792 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@RonnyPfannschmidt 已经在做这个了。

开始于 2026年10月17日。

  • #793 来自 @Sandeep1519-droid —— 已关闭,未合并
  • #799 来自 @RonnyPfannschmidt —— 未关闭

评估

难度
2/5
预计耗时
半天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
devtools

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
1.7k
派生
187
平均合并
1 天 20 小时
30 天内合并 PR
24

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytest-dev/pluggy 的其他 Issue

查看 pytest-dev/pluggy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。