diff --git a/HACKING.rst b/HACKING.rst index 31da34521df..18b63422c11 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -16,6 +16,7 @@ Below you can find a list of checks specific to this repository. - [N322] Detect common errors with assert_called_once_with - [N328] Detect wrong usage with assertEqual +- [N329] Use assertCountEqual() instead of assertItemsEqual() - [N330] Use assertEqual(*empty*, observed) instead of assertEqual(observed, *empty*) - [N331] Detect wrong usage with assertTrue(isinstance()). diff --git a/neutron/hacking/checks.py b/neutron/hacking/checks.py index 6a8ee69b04d..8043b53890d 100644 --- a/neutron/hacking/checks.py +++ b/neutron/hacking/checks.py @@ -91,9 +91,9 @@ def check_asserttruefalse(logical_line, filename): @core.flake8ext def check_assertitemsequal(logical_line, filename): - """N328 - Don't use assertItemsEqual.""" + """N329 - Don't use assertItemsEqual.""" if 'neutron/tests/' in filename: - if re.search(r"assertItemsEqual\(", logical_line): + if re.search(r"assertItemsEqual[\(,]", logical_line): msg = ("N329: Use assertCountEqual() instead of " "assertItemsEqual()") yield (0, msg) diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py index 3bd6ef4aa3b..e3fb7ad0b6e 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_impl_idl.py @@ -244,7 +244,7 @@ class TestNbApi(BaseOvnIdlTest): exp_values = [(lb['name'], lb['external_ids']) for lb in self.data['lbs']] lbs_values = [(lb.name, lb.external_ids) for lb in lbs] - self.assertItemsEqual(exp_values, lbs_values) + self.assertCountEqual(exp_values, lbs_values) def test_get_router_floatingip_lbs(self): f = self.nbapi.get_router_floatingip_lbs @@ -260,7 +260,7 @@ class TestNbApi(BaseOvnIdlTest): lbs_values = [(lb.name, lb.external_ids) for lb in f(exp_router_name)] self.assertTrue(exp_values) - self.assertItemsEqual(exp_values, lbs_values) + self.assertCountEqual(exp_values, lbs_values) def test_get_floatingip_in_nat_or_lb(self): f = self.nbapi.get_floatingip_in_nat_or_lb diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py index 0687661eefb..216f29fc93a 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovn_db_sync.py @@ -1429,9 +1429,9 @@ class TestOvnNbSync(base.TestOVNFunctionalBase): nb_pfs.append(pf) if should_match: - self.assertItemsEqual(nb_pfs, db_pfs) + self.assertCountEqual(nb_pfs, db_pfs) else: - self.assertRaises(AssertionError, self.assertItemsEqual, + self.assertRaises(AssertionError, self.assertCountEqual, nb_pfs, db_pfs) def _validate_port_groups(self, should_match=True): diff --git a/tox.ini b/tox.ini index dfff3509e7d..e5baebc6863 100644 --- a/tox.ini +++ b/tox.ini @@ -185,6 +185,7 @@ extension = # Checks specific to neutron repo N322 = neutron.hacking.checks:check_assert_called_once_with N328 = neutron.hacking.checks:check_asserttruefalse + N329 = neutron.hacking.checks:check_assertitemsequal N330 = neutron.hacking.checks:check_assertempty N331 = neutron.hacking.checks:check_assertisinstance N332 = neutron.hacking.checks:check_assertequal_for_httpcode