SIENTIAPDE-1646
Fix flaky shutdown assertions in test suite GC-collected instances during tests also invoke patched shutdown, making assert_called_once_with flaky. Count calls for this instance specifically instead of asserting total call count.
This commit is contained in:
@@ -386,7 +386,8 @@ def test_close(mock_shutdown, api):
|
|||||||
api.close()
|
api.close()
|
||||||
|
|
||||||
api.pi_web_api_client.close.assert_called_once()
|
api.pi_web_api_client.close.assert_called_once()
|
||||||
mock_shutdown.assert_called_once_with(api)
|
# Other instances collected by GC during the test also hit the patched shutdown.
|
||||||
|
assert mock_shutdown.call_args_list.count(call(api)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_process_pi_web_api_response_success(api):
|
def test_process_pi_web_api_response_success(api):
|
||||||
|
|||||||
@@ -991,7 +991,8 @@ def test_close_disposes_minio_repository(mock_shutdown):
|
|||||||
gates.close()
|
gates.close()
|
||||||
minio.close.assert_called_once()
|
minio.close.assert_called_once()
|
||||||
assert gates.minio_repository is None
|
assert gates.minio_repository is None
|
||||||
mock_shutdown.assert_called_once_with(gates)
|
# Other instances collected by GC during the test also hit the patched shutdown.
|
||||||
|
assert mock_shutdown.call_args_list.count(call(gates)) == 1
|
||||||
|
|
||||||
|
|
||||||
@patch.object(SientiaMonitoring, 'shutdown')
|
@patch.object(SientiaMonitoring, 'shutdown')
|
||||||
@@ -1004,4 +1005,5 @@ def test_close_without_minio_repository(mock_shutdown):
|
|||||||
metrics_controller=MagicMock(spec=MetricsController),
|
metrics_controller=MagicMock(spec=MetricsController),
|
||||||
)
|
)
|
||||||
gates.close()
|
gates.close()
|
||||||
mock_shutdown.assert_called_once_with(gates)
|
# Other instances collected by GC during the test also hit the patched shutdown.
|
||||||
|
assert mock_shutdown.call_args_list.count(call(gates)) == 1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
from unittest.mock import ANY, MagicMock, patch
|
from unittest.mock import ANY, MagicMock, call, patch
|
||||||
|
|
||||||
from pytest import fixture, raises
|
from pytest import fixture, raises
|
||||||
from sientia_do.notifications.models import NotificationLevel
|
from sientia_do.notifications.models import NotificationLevel
|
||||||
@@ -134,7 +134,8 @@ def test_close(storage, _patch_monitoring_shutdown):
|
|||||||
storage.close()
|
storage.close()
|
||||||
|
|
||||||
assert storage.minio_repository is None
|
assert storage.minio_repository is None
|
||||||
_patch_monitoring_shutdown.assert_called_once_with(storage)
|
# Other instances collected by GC during the test also hit the patched shutdown.
|
||||||
|
assert _patch_monitoring_shutdown.call_args_list.count(call(storage)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_close_when_minio_repository_already_none(storage, _patch_monitoring_shutdown):
|
def test_close_when_minio_repository_already_none(storage, _patch_monitoring_shutdown):
|
||||||
@@ -144,7 +145,8 @@ def test_close_when_minio_repository_already_none(storage, _patch_monitoring_shu
|
|||||||
storage.close()
|
storage.close()
|
||||||
|
|
||||||
assert storage.minio_repository is None
|
assert storage.minio_repository is None
|
||||||
_patch_monitoring_shutdown.assert_called_once_with(storage)
|
# Other instances collected by GC during the test also hit the patched shutdown.
|
||||||
|
assert _patch_monitoring_shutdown.call_args_list.count(call(storage)) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_load_query_with_minio_offload_no_rows(storage):
|
def test_load_query_with_minio_offload_no_rows(storage):
|
||||||
|
|||||||
Reference in New Issue
Block a user