diff options
| author | Xavier Morel <xmo@odoo.com> | 2020-01-29 12:11:24 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2020-02-04 12:42:35 +0000 |
| commit | b1e58ab6c621a4df4b9413eaf4dcb58e9e8d46ed (patch) | |
| tree | bc979a40570bb65e5c08f9f691c039f995ed2579 /addons/product/tests | |
| parent | 672709c125dae6dfb1e8931b656c04993315cf4e (diff) | |
[FIX] product: deprecation warning triggered by assertion
Replace an assertRaises(StopIteration) by a next() with a default
value.
Following PEP 479, *any* StopIteration reaching the toplevel of a
generator triggers a DeprecationWarning. And while the assertRaises
looks innocuous, both _assertRaises and the underlying
clear_upon_failure are implemented with functools.contextmanager,
which wraps a generator.
As a result, exceptions raised in the assertRaises "body" get
reinjected inside the wrapped context manager[0] and if the exception
is a StopIteration it triggers the warning.
By not using assertRaises we side-step the issue.
[0] https://github.com/python/cpython/blob/b6999e5690c7006b0ba4049cfd638513c982a90c/Lib/contextlib.py#L131
Diffstat (limited to 'addons/product/tests')
| -rw-r--r-- | addons/product/tests/test_product_attribute_value_config.py | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/addons/product/tests/test_product_attribute_value_config.py b/addons/product/tests/test_product_attribute_value_config.py index 12d27b59c6f..3c672523e6e 100644 --- a/addons/product/tests/test_product_attribute_value_config.py +++ b/addons/product/tests/test_product_attribute_value_config.py @@ -352,8 +352,7 @@ class TestProductAttributeValueConfig(TestProductAttributeValueCommon): self.assertEqual(next(gen), computer_ssd_512 + computer_ram_32 + computer_hdd_1) self.assertEqual(next(gen), computer_ssd_512 + computer_ram_32 + computer_hdd_2) self.assertEqual(next(gen), computer_ssd_512 + computer_ram_32 + computer_hdd_4) - with self.assertRaises(StopIteration): - next(gen) + self.assertIsNone(next(gen, None)) # Give priority to ram_16 but it is not allowed by hdd_1 so it should return hhd_2 instead # Test invalidate_cache on product.attribute.value write @@ -392,8 +391,7 @@ class TestProductAttributeValueConfig(TestProductAttributeValueCommon): self._add_exclude(computer_ram_32, computer_hdd_4) self.assertEqual(self.computer._get_first_possible_combination(), self.env['product.template.attribute.value']) gen = self.computer._get_possible_combinations() - with self.assertRaises(StopIteration): - next(gen) + self.assertIsNone(next(gen, None)) def test_get_closest_possible_combinations(self): computer_ssd_256 = self._get_product_template_attribute_value(self.ssd_256) @@ -417,8 +415,7 @@ class TestProductAttributeValueConfig(TestProductAttributeValueCommon): self.assertEqual(next(gen), computer_ssd_256 + computer_ram_32 + computer_hdd_1) self.assertEqual(next(gen), computer_ssd_512 + computer_ram_8 + computer_hdd_1) self.assertEqual(next(gen), computer_ssd_512 + computer_ram_32 + computer_hdd_1) - with self.assertRaises(StopIteration): - next(gen) + self.assertIsNone(next(gen, None)) # CASE contains computer_hdd_2 self.assertEqual(self.computer._get_closest_possible_combination(computer_hdd_2), |
