unittest.mock: Double period in AttributeError message for invalid assertion methods
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
When accessing a non-existent assertion method on a [Mock] object( e.g., assert_called_twice_with), the raised [AttributeError] message contains a double period (..) before the "Did you mean" suggestion.
Example
import unittest.mock as mock
m = mock.Mock()
m.assert_called_twice_with(1, 2)
Output
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.12/unittest/mock.py", line 665, in __getattr__
raise AttributeError(
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute.. Did you mean: 'assert_called_once_with'?
Problem
Note the double period ([attribute.. Did you mean] in the error message.
Expected Behavior
The error message should contain only a single period before the suggestion, e.g.:
Expected Output
AttributeError: 'assert_called_twice_with' is not a valid assertion. Use a spec for the mock if 'assert_called_twice_with' is meant to be an attribute. Did you mean: 'assert_called_once_with'?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PR
Linked PRs
- gh-137717
- gh-138111
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en unittest/mock.py, en Mock.getattr, el punto de entrada mostrado en el traceback. Comprueba las pruebas existentes de unittest.mock para métodos de aserción no válidos y ajusta el mensaje para que la sugerencia siga a un único punto; las pruebas correspondientes deberían confirmar el texto corregido de AttributeError.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- testing-qa
- Tipo de issue
- Error
- Dificultad
- 1/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100