python / python/cpython

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

Offen
#94,478 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stdlib type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
36k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne bei der _patch-Klasse und ihrer enter-Methode, in der die Klass-Instanz erstellt wird, und untersuche, wie unsafe an Mock übergeben wird. Aktualisiere die relevanten Testfälle, um zu zeigen, dass unsafe=True die gemockten Instanzen erreicht und dass sich ihr interner unsafe-Zustand entsprechend ändert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
testing-qa
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.