When mocking with `unsafe=True` the mocked instances don't receive the unsafe argument.

Aperta
#94,478 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
testing-qa

Direzione di ricerca

Inizia dalla classe _patch e dal suo metodo enter, dove viene creata l’istanza di Klass, e verifica come unsafe viene passato a Mock. Aggiorna i casi di test pertinenti per dimostrare che unsafe=True raggiunge le istanze mockate e che il loro stato interno unsafe cambia di conseguenza.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

stdlib type-bug

Bug report

When the feature Check against misspellings of assert etc. in mock was introduced, the unsafe flag was moved out from kwargs and defined as a named argument.
Previously since unsafe was implicitly part of kwargs, it was silently propagated from _patch class to the instantiation of the klass variable inside the __enter__ method.
But now, the unsafe flag as an explicitly named argument is not being propagated to the instantiation of the Klass variable.
Hence the Mock class is unable to set its internal attribute _mock_unsafe and will always be False regardless of whether the user set unsafe=True or not.

The test cases have to be updated to show this bug.

This bug was introduced in this commit: fdb9efce6ac211f973088eef508740c3fa2bd182 (bpo-41877) and only included in versions from Python 3.10.

Your environment

  • CPython versions tested on: 3.10, 3.11 and master branch.
  • Operating system and architecture: Ubuntu 22.04
Lingua principale
Python
Stelle
77.2k
Fork
36k
Merge medio
1g 9h
PR unite (30g)
558

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/cpython

Tutte le issue di python/cpython

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.