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).

الانتقال إلى التثبيت

معلومات المصدر

المستودع
cajias/claude-skills
آخر نشاط في المصدر
٢٠ يوليو ٢٠٢٦ في ٠٧:٢٩
لغة SKILL.md المكتشفة
الإنجليزية
النجوم
٠
التفرعات
٠

خيارات التثبيت

يُحدَّد Prompt الذي يراجع المصدر أولًا بشكل افتراضي. يمكنك التبديل إلى أمر مباشر أو تنزيل نسخة محلية.

مراجعة ملفات المصدر

اقرأ SKILL.md وأي ملفات مرافقة يعرضها SkillsMP قبل أن تقرر التثبيت.