unittest.mock: Double period in AttributeError message for invalid assertion methods
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in unittest/mock.py, in Mock.getattr, il punto di ingresso mostrato nel traceback. Controlla i test unittest.mock esistenti per i metodi di asserzione non validi e modifica il messaggio in modo che il suggerimento segua un singolo punto; i test pertinenti dovrebbero confermare il testo corretto di AttributeError.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing-qa
- Tipo di issue
- Bug
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 25/100