Skip to content

Keep hook tracing from crashing on impostor values - #799

Open
RonnyPfannschmidt wants to merge 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:fix-792-tracing-robust
Open

RonnyPfannschmidt wants to merge 1 commit into
pytest-dev:mainfrom
RonnyPfannschmidt:fix-792-tracing-robust

Conversation

@RonnyPfannschmidt

Copy link
Copy Markdown
Member

Written by Claude Opus 5.5 via Claude Code for the pluggy maintainers; I prompted it, it did the work, I read it.

Fixes #792.

  • Formatting is now chosen from type() rather than isinstance(). isinstance() trusts __class__, so Mock(spec=str) / Mock(spec=dict) were sent down the str/dict paths and raised TypeError from inside the hook call.
  • enable_tracing now ends the "finish" message with an explicit {}. Before, a hook that returned a dict had its result listed as if it were the call's arguments.
  • Formatting a value goes through the same failure guard as str()/repr(). A failure shows up in the trace and is not raised.

Supersedes the closed #793 and #796.

Choose the rendering from type(), since isinstance() trusts __class__ and
a Mock(spec=str) or Mock(spec=dict) claims a type whose methods it lacks.
Pass an explicit empty mapping after a hook result, so a dict result is
traced as the result instead of as call arguments. Route value formatting
through the same failure guard as str() and repr().

Co-Authored-By: Claude Opus 5.5 via Claude Code <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hook tracing crashes with specced Mock arguments and results

1 participant