Skip to content

Commit 412b482

Browse files
committed
test(proto-plus): use patch.dict for safe dictionary manipulation in tests
Follows reviewer suggestion to avoid potential test pollution.
1 parent 693e0d0 commit 412b482

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

packages/proto-plus/tests/test_marshal_thread_safety.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,12 @@ class FakeMarshal:
4747

4848
m = Marshal(name="default")
4949

50-
# Inject FakeMarshal into Marshal._instances
51-
Marshal._instances["fake_uninitialized"] = FakeMarshal()
50+
# Inject FakeMarshal into Marshal._instances safely using patch.dict
51+
with patch.dict(Marshal._instances, {"fake_uninitialized": FakeMarshal()}):
5252

53-
class DummyType:
54-
pass
55-
56-
# This should not raise AttributeError because of getattr safety
57-
rule = m.get_rule(DummyType)
58-
assert rule == m._noop
53+
class DummyType:
54+
pass
5955

60-
# Clean up
61-
del Marshal._instances["fake_uninitialized"]
56+
# This should not raise AttributeError because of getattr safety
57+
rule = m.get_rule(DummyType)
58+
assert rule == m._noop

0 commit comments

Comments
 (0)