mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
torch/config: fix mock behaviour (#140779)
Mock only replaces the value that was removed, if after deletion, it does not see the attribute. Pull Request resolved: https://github.com/pytorch/pytorch/pull/140779 Approved by: https://github.com/ezyang
This commit is contained in:
committed by
PyTorch MergeBot
parent
878a849c92
commit
241d2259d3
@ -1,6 +1,7 @@
|
||||
# Owner(s): ["module: unknown"]
|
||||
import os
|
||||
import pickle
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
os.environ["ENV_TRUE"] = "1"
|
||||
@ -320,6 +321,14 @@ torch.testing._internal.fake_config_module._save_config_ignore = ['e_ignored']""
|
||||
revert()
|
||||
self.assertTrue(config.e_bool)
|
||||
|
||||
def test_unittest_patch(self):
|
||||
with patch("torch.testing._internal.fake_config_module.e_bool", False):
|
||||
with patch("torch.testing._internal.fake_config_module.e_bool", False):
|
||||
self.assertFalse(config.e_bool)
|
||||
# unittest.mock has some very weird semantics around deletion of attributes when undoing patches
|
||||
self.assertFalse(config.e_bool)
|
||||
self.assertTrue(config.e_bool)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
Reference in New Issue
Block a user