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
There are times when a classmethod makes sense - e.g. a classmethod can be called in setUpTestData whereas an instance method cannot. While this implementation is using a basic string attr, it's more critical in the case of an object attr where we may want to call that classmethod again at test runtime, however with wrap_testdata the value of the attr is the original state that was set in setUpTestData and doesn't include the changes made in the test itself.
We could refresh the value in the classmethod, however that would break wrap_testdata as now the class will have the modified version from the test going forward.
The text was updated successfully, but these errors were encountered:
however with wrap_testdata the value of the attr is the original state that was set in setUpTestData and doesn't include the changes made in the test itself.
That's just how attribute assignment works in Python, if you do assert self.foo == 'baz' in test_baz you'll notice that the assignment worked properly.
classcls:
foo='bar'assertcls.foo=='bar'self=cls()
assertself.foo=='bar'# Since self.__dict__['foo'] is missing it falls back to cls.__dict__['foo']self.foo='baz'# Assigns self.__dict__['foo'] = 'baz' and leaves cls.__dict__['foo'] untouchedassertcls.foo=='bar'assertself.foo=='baz'
In the example you provided, even with the decorator removed, the attribute assignment flow is the following:
vaidate; assert TestFoo.__dict__['foo'] == 'baz' which fails
In other words, doing self.foo = 'baz' doesn't alter TestFoo.foo in any way (that's just how class instance attribute assignment works in Python) and the testdata descriptor won't interfere with that at all.
The issue description here is admittedly terrible, so here is an example of a test that will fail to make it clearer:
There are times when a classmethod makes sense - e.g. a classmethod can be called in
setUpTestData
whereas an instance method cannot. While this implementation is using a basic string attr, it's more critical in the case of an object attr where we may want to call that classmethod again at test runtime, however withwrap_testdata
the value of the attr is the original state that was set insetUpTestData
and doesn't include the changes made in the test itself.We could refresh the value in the classmethod, however that would break
wrap_testdata
as now the class will have the modified version from the test going forward.The text was updated successfully, but these errors were encountered: