Skip to main content

python-slots-mock-patch-object

Fix for `AttributeError: '<ClassName>' object attribute '<method>' is read-only` raised during `mock.patch.object()` teardown. Use when: (1) a Python test using `unittest.mock.patch.object(instance, "method")` passes the patched code but raises an AttributeError during context-exit (visible in the stack as `mock.py:1635` calling `delattr(self.target, self.attribute)`); (2) the target class declares `__slots__`; (3) the test was working before someone added `__slots__` to a base class or the target class itself; (4) a refactor introduced `__slots__` "for efficiency" and broke a previously-green test suite. Covers root cause (`__slots__` blocks `delattr` because it doesn't allocate `__dict__`, so the attribute can't be removed after the patch sets it), the diagnostic signature, the canonical fix (drop `__slots__` if the class is a mock target), and when `__slots__` IS the right call (when memory matters AND the class is never patched).

Aller à l'installation

Informations de source

Dépôt
cajias/claude-skills
Dernière activité de la source
20 juillet 2026 à 07:29
Langue détectée de SKILL.md
anglais
Étoiles
0
Forks
0

Options d'installation

Le prompt qui vérifie d'abord la source est sélectionné par défaut. Vous pouvez passer à une commande directe ou télécharger une copie locale.

Vérifiez les fichiers source

Lisez SKILL.md et les fichiers associés affichés par SkillsMP avant de décider de l'installer.