From 3b224b562972f4ab4f127aafec80fb76b7952eaf Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Tue, 14 Nov 2023 10:38:40 +0000 Subject: [PATCH] Fix object tests A couple of object tests are failing, probably after a dependency bump. watcher.objects.base.objects is mocked, so the registered object version isn't properly retrieved, leading to a type error: File "/mnt/data/workspace/watcher/watcher/tests/objects/test_objects.py", line 535, in test_hook_chooses_newer_properly reg.registration_hook(MyObj, 0) File "/mnt/data/workspace/watcher/watcher/objects/base.py", line 46, in registration_hook cur_version = versionutils.convert_version_to_tuple( File "/home/ubuntu/openstack_venv/lib/python3.10/site-packages/oslo_utils/versionutils.py", line 91, in convert_version_to_tuple version_str = re.sub(r'(\d+)(a|alpha|b|beta|rc)\d+$', '\\1', version_str) File "/usr/lib/python3.10/re.py", line 209, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: expected string or bytes-like object We'll solve the issue by setting the VERSION attribute against the mock object. Change-Id: Ifeb38b98f1d702908531de5fc5c846bd1c53de4b --- watcher/tests/objects/test_objects.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/watcher/tests/objects/test_objects.py b/watcher/tests/objects/test_objects.py index b40e33a44..8c40dde30 100644 --- a/watcher/tests/objects/test_objects.py +++ b/watcher/tests/objects/test_objects.py @@ -531,6 +531,7 @@ class TestRegistry(test_base.TestCase): @mock.patch('watcher.objects.base.objects') def test_hook_chooses_newer_properly(self, mock_objects): + mock_objects.MyObj.VERSION = MyObj.VERSION reg = base.WatcherObjectRegistry() reg.registration_hook(MyObj, 0) @@ -547,6 +548,7 @@ class TestRegistry(test_base.TestCase): @mock.patch('watcher.objects.base.objects') def test_hook_keeps_newer_properly(self, mock_objects): + mock_objects.MyObj.VERSION = MyObj.VERSION reg = base.WatcherObjectRegistry() reg.registration_hook(MyObj, 0)