Mocks created by mocker.patch.multiple are not handled like other patches
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 78/100
Direzione di ricerca
Start by tracing mocker.patch.multiple() and the registration and warning hooks used by mocker.stop(). Reproduce both failures with the examples in the issue, then add regression coverage showing that each returned mock can be used as a context manager and stopped individually. Done means the existing mocker.stop(mocks) behavior and the other patch APIs continue to work.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
mocker.patch.multiple() returns a dict of the mocks it created, and pytest-mock only registers that dict. #629 made resetall() reset the mocks inside it, but two other features still treat the dict as the mock:
-
No context-manager warning. The
PytestMockWarninghook is only installed on the dict (where it does nothing), not on the mocks:def test_multiple_warning(mocker): mocks = mocker.patch.multiple(Target, a=mocker.DEFAULT) with pytest.warns(PytestMockWarning): # fails: DID NOT WARN with mocks["a"]: passwith mocker.patch.object(Target, "a"):does warn. -
mocker.stop()can't stop a single mock.def test_multiple_stop_one(mocker): mocks = mocker.patch.multiple(Target, a=mocker.DEFAULT, b=mocker.DEFAULT) mocker.stop(mocks["a"]) # ValueError: This mock object is not registeredOnly
mocker.stop(mocks)works, which undoes all of them. Supporting single mocks would need each attribute's patcher to be stopped on its own.
Both reproduced on 3.16.1 (Target is any class with attributes a and b).
- Lingua principale
- Python
- Stelle
- 2k
- Fork
- 181
- Merge medio
- 1g 22h
- PR unite (30g)
- 25
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi 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.
Altre issue di pytest-dev/pytest-mock
-
resetall(side_effect=True) removes the warning about using mocks as context managersForse già presa @Parsiffall1 l’ha presa 3 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
pytest-dev/pytest-mock#637 ·
I maintainer di solito rispondono entro 1 giorno
-
spy.reset_mock(side_effect=True) makes spies stop calling the spied codeForse già presa @saifmodan2006 l’ha presa 3 giorni fa. Apertabug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
pytest-dev/pytest-mock#636 ·
I maintainer di solito rispondono entro 1 giorno
-
Spy with async function not registering calls until coroutine is awaitedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
pytest-dev/pytest-mock#519 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
mocker.stub() is a coroutine functionForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Apertaquestion
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
pytest-dev/pytest-mock#375 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 38/100
pytest-dev/pytest-mock#374 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytest-dev/pytest-mock
Issue simili
-
documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
selimfirat/pysad#379 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
open-webui/open-webui#32805 ·
I maintainer di solito rispondono entro 1 giorno
-
fix: [bug description] HTML CVE metric table shows only the last CVE for each productForse già presa @Chris-wh233 l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
ossf/cve-bin-tool#5976 ·
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
gke-labs/kube-agents#3615 ·
I maintainer di solito rispondono entro 1 giorno
-
deferred
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno