Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Hook tracing crashes with specced Mock arguments and results

Abierto
#792 2 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@RonnyPfannschmidt ya está trabajando en esto.

Desde el 17/10/2026.

  • #793 de @Sandeep1519-droid — cerrado sin fusionar
  • #799 de @RonnyPfannschmidt — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
Medio día
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
devtools

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
1.7k
Forks
187
Merge medio
1 d 20 h
PR fusionados (30 d)
24

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytest-dev/pluggy

Todos los issues de pytest-dev/pluggy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.