You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @fornellas, I got a question while refactoring the fix for this one, are classes attributes allowed to be patched at class level or should we enforce the same behavior as in for instance attributes?
For example, should the following work? (it works now)
class A:
ATTR: str = "ATTR"
class TestA(testslide.TestCase):
def test_class_attribute_work(self):
self.patch_attribute(A, "ATTR", "mock")
self.assertEqual(A.ATTR, "mock")
Attribute exists at the class, patching it there is no different from patching an attribute at a module or instance.
If it were to be patched at the instance, would only affect that instance, nothing more.
The issue here is when the attribute does not exist at the class, but only at the instance. Allowing to patch it at the class would mean not respecting the class interface (which does not have the attribute).
I crossed some wire when I mentioned mock_callable blocking patching instance methods at the class, which is a different issue rooted at this RSPec decision to not support it, as it is kind of a code smell, sorry about the confusion.
This:
yields:
However, patching instance attributes at classes should not be allowed.
mock_callable
already prevents that.Let's make patch_attribute refuse to patch instance attributes at classes as well.
Probably a good idea to reuse logic from
mock_callable
to define if "is this good to patch?".The text was updated successfully, but these errors were encountered: