From 41d821544d8dd15bb34f8555d5f6ea4972047771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ramos=20Carre=C3=B1o?= <carlos.ramos@nexedi.com> Date: Mon, 22 Apr 2024 22:39:13 +0900 Subject: [PATCH] Fix CMFCategory test in Python 2. - The warnings are compared in a set instead of a list, as we do not care of how many times is the warning raised. - The warning filter is added inside the context manager, as recommended in https://docs.python.org/2.7/library/warnings.html#testing-warnings . - We change the `clear` method of list, using `del` instead, as the `clear` method was added on Python 3.3. --- product/CMFCategory/tests/testCMFCategory.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/product/CMFCategory/tests/testCMFCategory.py b/product/CMFCategory/tests/testCMFCategory.py index f3c676a5ffa..b9efa46f6b0 100644 --- a/product/CMFCategory/tests/testCMFCategory.py +++ b/product/CMFCategory/tests/testCMFCategory.py @@ -1000,23 +1000,25 @@ class TestCMFCategory(ERP5TypeTestCase): # emitted. Because the method exists on both category and base category # there can be two warnings. with warnings.catch_warnings(record=True) as warning_list: + warnings.simplefilter("always") c1.getCategoryChildValueList(local_sort_method=sort_func) self.assertEqual( - [str(w.message) for w in warning_list], - ['`local_sort_method` argument is deprecated, use `local_sort_key` instead']) + {str(w.message) for w in warning_list}, + {'`local_sort_method` argument is deprecated, use `local_sort_key` instead'}) with warnings.catch_warnings(record=True) as warning_list: + warnings.simplefilter("always") bc.getCategoryChildValueList(local_sort_method=sort_func) self.assertEqual( - [str(w.message) for w in warning_list], - ['`local_sort_method` argument is deprecated, use `local_sort_key` instead'] * 2) + {str(w.message) for w in warning_list}, + {'`local_sort_method` argument is deprecated, use `local_sort_key` instead'}) - sort_func_calls.clear() + del sort_func_calls[:] # here c1, c2, c3 are sorted by their titles self.assertEqual(list(bc.getCategoryChildValueList( local_sort_method=sort_func)), [c3, c2, c1, c11, c111, c12]) self.assertTrue(sort_func_calls) - sort_func_calls.clear() + del sort_func_calls[:] # here c11 & c12 are sorted by their titles self.assertEqual(list(c1.getCategoryChildValueList( local_sort_method=sort_func)), [c11, c111, c12]) -- 2.30.9