From 0235db3d31a22274a667fc8d58d106c7314bfada Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Tue, 20 Jun 2023 16:27:05 -0700 Subject: [PATCH] tests: Stop trying to mutate instantiated EntryPoints py311 made EntryPoints immutable. Subclass instead. Closes-Bug: #2009228 Change-Id: I90198b1bb6b18b752e0fdc4d4d920914ea449413 --- test/unit/common/test_utils.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 5779dd4214..802c39001e 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -3840,22 +3840,25 @@ cluster_dfw1 = http://dfw1.host/v1/ @mock.patch('importlib.metadata.distribution') def test_load_pkg_resource_importlib(self, mock_driver): import importlib.metadata + + class TestEntryPoint(importlib.metadata.EntryPoint): + def load(self): + return self.value + repl_obj = object() ec_obj = object() other_obj = object() mock_driver.return_value.entry_points = [ - importlib.metadata.EntryPoint(group='swift.diskfile', - name='replication.fs', - value=repl_obj), - importlib.metadata.EntryPoint(group='swift.diskfile', - name='erasure_coding.fs', - value=ec_obj), - importlib.metadata.EntryPoint(group='swift.section', - name='thing.other', - value=other_obj), + TestEntryPoint(group='swift.diskfile', + name='replication.fs', + value=repl_obj), + TestEntryPoint(group='swift.diskfile', + name='erasure_coding.fs', + value=ec_obj), + TestEntryPoint(group='swift.section', + name='thing.other', + value=other_obj), ] - for ep in mock_driver.return_value.entry_points: - ep.load = lambda ep=ep: ep.value tests = { ('swift.diskfile', 'egg:swift#replication.fs'): repl_obj, ('swift.diskfile', 'egg:swift#erasure_coding.fs'): ec_obj,