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

Assertion diff doesn't pretty-print the built-in frozen dict (Python 3.15)

Abierto Apto para principiantes
#15,172 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@HakeemTheEmperor ya está trabajando en esto.

Desde el 13/10/2026.

  • #1 de @isaqciosperonic-ux — abierto
  • #15173 de @HakeemTheEmperor — abierto
  • #15207 de @isaqciosperonic-ux — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
testing

Línea de trabajo

La corrección debe ir en src/_pytest/_io/pprint.py. Lee PrettyPrinter._dispatch y el manejador existente _pprint_ordered_dict, y luego añade un manejador para frozendict que solo se registre cuando exista el tipo frozendict, para que las versiones antiguas de Python no se vean afectadas. Reproduce el problema con la lista de dos elementos de frozendicts del issue usando pytest -vv. Está terminado cuando el Full diff coloca las claves de cada frozendict en líneas separadas y se marca el valor cambiado de age, y cuando pasa un test que cubre el nuevo manejador.

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

Descripción

Python 3.15 added frozendict as a built-in type (PEP 814). When an assertion
comparing frozendicts fails with -vv, the "Full diff" prints each frozendict on
a single line. A dict with the same contents gets one key per line, which makes
the changed value easy to spot. With frozendict the change is buried mid-line.

def test_frozendict():
    left = [frozendict(name='alice', age=30, city='Lagos'), frozendict(name='bob', age=25, city='Abuja')]
    right = [frozendict(name='alice', age=30, city='Lagos'), frozendict(name='bob', age=26, city='Abuja')]
    assert left == right

Output with pytest -vv:

Full diff:
  [
      frozendict({'name': 'alice', 'age': 30, 'city': 'Lagos'}),
-     frozendict({'name': 'bob', 'age': 26, 'city': 'Abuja'}),
?                                        ^
+     frozendict({'name': 'bob', 'age': 25, 'city': 'Abuja'}),
?                                        ^
  ]

The same test using dict:

Full diff:
  [
      {
          'name': 'alice',
          'age': 30,
          'city': 'Lagos',
      },
      {
          'name': 'bob',
-         'age': 26,
?                 ^
+         'age': 25,
?                 ^
          'city': 'Abuja',
      },
  ]

I think the cause is in src/_pytest/_io/pprint.py. PrettyPrinter._dispatch
has handlers for dict, OrderedDict, defaultdict, MappingProxyType and
others, but not frozendict, so it falls back to a one-line repr(). The
standard library's pprint in 3.15 already supports frozendict.

A possible fix is a _pprint_frozendict handler similar to _pprint_ordered_dict,
registered only when frozendict exists, so older Python versions aren't affected.

Versions

pytest 9.1.1, Python 3.15.0, Windows 11. Also seen on pytest main with Python 3.15 on Linux.

pip list
Package   Version
--------- -------
colorama  0.4.6
iniconfig 2.3.1
packaging 26.3
pip       26.2.1
pluggy    1.6.0
Pygments  2.21.0
pytest    9.1.1

I'm happy to open a PR for this.

Lenguaje dominante
Python
Estrellas
14.6k
Forks
3.5k
Merge medio
1 d 17 h
PR fusionados (30 d)
25

Preparar el entorno

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

Todos los issues de pytest-dev/pytest

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.