Skip to content

Commit

Permalink
Fix unit tests for Python 3.11
Browse files Browse the repository at this point in the history
Mocks can no longer be provided as the specs for other Mocks.
See python/cpython#87644 and
https://docs.python.org/3.11/whatsnew/3.11.html for more info.

Change-Id: If7c10d9bfd0bb410b3bc5180b737439c92e515da
  • Loading branch information
elfosardo committed Dec 7, 2022
1 parent 4d66609 commit 342f4b3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions ironic/tests/unit/drivers/modules/irmc/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def test_inspect_hardware(self, power_state_mock, _inspect_hardware_mock,
_inspect_hardware_mock.return_value = (inspected_props,
inspected_macs,
new_traits)
new_port_mock1 = mock.MagicMock(spec=objects.Port)
new_port_mock2 = mock.MagicMock(spec=objects.Port)
new_port_mock1 = objects.Port
new_port_mock2 = objects.Port

port_mock.side_effect = [new_port_mock1, new_port_mock2]

Expand All @@ -220,11 +220,11 @@ def test_inspect_hardware(self, power_state_mock, _inspect_hardware_mock,
port_mock.assert_has_calls([
mock.call(task.context, address=inspected_macs[0],
node_id=node_id),
mock.call.create(),
mock.call(task.context, address=inspected_macs[1],
node_id=node_id)
])
new_port_mock1.create.assert_called_once_with()
new_port_mock2.create.assert_called_once_with()
node_id=node_id),
mock.call.create()
], any_order=False)

self.assertTrue(info_mock.called)
task.node.refresh()
Expand Down Expand Up @@ -259,8 +259,9 @@ def test_inspect_hardware_with_power_off(self, power_state_mock,
_inspect_hardware_mock.return_value = (inspected_props,
inspected_macs,
new_traits)
new_port_mock1 = mock.MagicMock(spec=objects.Port)
new_port_mock2 = mock.MagicMock(spec=objects.Port)

new_port_mock1 = objects.Port
new_port_mock2 = objects.Port

port_mock.side_effect = [new_port_mock1, new_port_mock2]

Expand All @@ -276,11 +277,11 @@ def test_inspect_hardware_with_power_off(self, power_state_mock,
port_mock.assert_has_calls([
mock.call(task.context, address=inspected_macs[0],
node_id=node_id),
mock.call.create(),
mock.call(task.context, address=inspected_macs[1],
node_id=node_id)
])
new_port_mock1.create.assert_called_once_with()
new_port_mock2.create.assert_called_once_with()
node_id=node_id),
mock.call.create()
], any_order=False)

self.assertTrue(info_mock.called)
task.node.refresh()
Expand Down

0 comments on commit 342f4b3

Please sign in to comment.