Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/patch_attribute_testslide.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,9 @@ def patch_attribute_passes_for_private_with_allow_private(self):
self.patch_attribute(
sample_module.SomeClass, "_private_attr", "notsoprivate", allow_private=True
)

@context.example
def unpatching_restores_falsy_values(self):
self.patch_attribute(sample_module.SomeUnhashableClass, "class_attr", 1)
unpatch_all_mocked_attributes()
self.assertEqual(sample_module.SomeUnhashableClass.class_attr, 0)
4 changes: 2 additions & 2 deletions testslide/core/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _patch(
setattr(type(target), attribute, property(fget=lambda _: new_value))

def unpatcher() -> None:
if restore_value:
if restore or restore_value:
setattr(type(target), attribute, original_property)
else:
delattr(target, attribute)
Expand All @@ -105,7 +105,7 @@ def unpatcher() -> None:
setattr(target, attribute, new_value)

def unpatcher() -> None:
if restore_value:
if restore or restore_value:
setattr(target, attribute, restore_value)

else:
Expand Down