Skip to content

Commit d3ed2c9

Browse files
author
Marcin Wilk
committed
Fix Python 3.12 unittest compatibility
Python 3.12 has removed long-deprecated unittest features [1], therefore some of the existing unit test fail when run on Python 3.12. This patch replaces the 'assertEquals' with 'assertTrue' or 'assertFalse', depending on the usage. This patch also fixes the 'test_amqp_changed' and 'test_amqp_departed' test methods which improperly called 'called_with' which is no longer a valid assertion method [2]. And in fact on Python < 3.12 the 'test_amqp_changed' and 'test_amqp_departed' pass their assertions, when they actually should fail due to the out-of-sync with 'amqp-relation-changed' and 'amqp-relation-departed' hook code. In this case the 'called_with' is replaced with 'assert_called_once'. [1] https://docs.python.org/3.12/whatsnew/3.12.html#id3 [2] python/cpython#100690 Change-Id: I90b400f6bafe8f03f04f991d9fe58635d19b8b2e Signed-off-by: Marcin Wilk <[email protected]> (cherry picked from commit 6346564)
1 parent e009964 commit d3ed2c9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

unit_tests/test_neutron_ovs_hooks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ def test_amqp_joined(self):
309309
def test_amqp_changed(self):
310310
self.CONFIGS.complete_contexts.return_value = ['amqp']
311311
self._call_hook('amqp-relation-changed')
312-
self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF))
312+
self.CONFIGS.write_all.assert_called_once()
313313

314314
def test_amqp_departed(self):
315+
self.CONFIGS.complete_contexts.return_value = ['amqp']
315316
self._call_hook('amqp-relation-departed')
316-
self.assertTrue(self.CONFIGS.write.called_with(NEUTRON_CONF))
317+
self.CONFIGS.write_all.assert_called_once()

unit_tests/test_neutron_ovs_utils.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -1261,43 +1261,43 @@ def test_enable_ovs_dpdk_vhostuser_client(
12611261
def test_use_dvr(self, _is_container, _NeutronAPIContext):
12621262
_is_container.return_value = False
12631263
_NeutronAPIContext()().get.return_value = True
1264-
self.assertEquals(nutils.use_dvr(), True)
1264+
self.assertTrue(nutils.use_dvr())
12651265
_is_container.return_value = True
1266-
self.assertEquals(nutils.use_dvr(), False)
1266+
self.assertFalse(nutils.use_dvr())
12671267

12681268
@patch.object(nutils.context, 'NeutronAPIContext')
12691269
@patch.object(nutils, 'is_container')
12701270
def test_use_l3ha(self, _is_container, _NeutronAPIContext):
12711271
_is_container.return_value = False
12721272
_NeutronAPIContext()().get.return_value = True
1273-
self.assertEquals(nutils.use_l3ha(), True)
1273+
self.assertTrue(nutils.use_l3ha())
12741274
_is_container.return_value = True
1275-
self.assertEquals(nutils.use_l3ha(), False)
1275+
self.assertFalse(nutils.use_l3ha())
12761276

12771277
@patch.object(nutils.context, 'NeutronAPIContext')
12781278
@patch.object(nutils, 'is_container')
12791279
def test_enable_nova_metadata(self, _is_container, _NeutronAPIContext):
12801280
_is_container.return_value = False
12811281
_NeutronAPIContext()().get.return_value = True
1282-
self.assertEquals(nutils.enable_nova_metadata(), True)
1282+
self.assertTrue(nutils.enable_nova_metadata())
12831283
_is_container.return_value = True
1284-
self.assertEquals(nutils.enable_nova_metadata(), False)
1284+
self.assertFalse(nutils.enable_nova_metadata())
12851285

12861286
@patch.object(nutils, 'config')
12871287
@patch.object(nutils, 'is_container')
12881288
def test_enable_local_dhcp(self, _is_container, _config):
12891289
_is_container.return_value = False
12901290
_config.return_value = True
1291-
self.assertEquals(nutils.enable_local_dhcp(), True)
1291+
self.assertTrue(nutils.enable_local_dhcp())
12921292
_is_container.return_value = True
1293-
self.assertEquals(nutils.enable_local_dhcp(), False)
1293+
self.assertFalse(nutils.enable_local_dhcp())
12941294

12951295
@patch.object(nutils, 'kv')
12961296
def test_use_fqdn_hint(self, _kv):
12971297
_kv().get.return_value = False
1298-
self.assertEquals(nutils.use_fqdn_hint(), False)
1298+
self.assertFalse(nutils.use_fqdn_hint())
12991299
_kv().get.return_value = True
1300-
self.assertEquals(nutils.use_fqdn_hint(), True)
1300+
self.assertTrue(nutils.use_fqdn_hint())
13011301

13021302
def test_use_hw_offload_rocky(self):
13031303
self.os_release.return_value = 'rocky'

0 commit comments

Comments
 (0)