Fix pytests to make them run in isolation (#5878)

This commit is contained in:
Stefan Agner 2025-05-12 12:37:09 +02:00 committed by GitHub
parent ff849ce692
commit b9bbb99f37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 56 additions and 17 deletions

View File

@ -730,6 +730,7 @@ async def test_local_example_start(
container: MagicMock,
tmp_supervisor_data: Path,
install_addon_example: Addon,
path_extern,
):
"""Test start of an addon."""
install_addon_example.path_data.mkdir()

View File

@ -217,7 +217,9 @@ async def test_do_backup_partial_maximal(
assert coresys.core.state == CoreState.RUNNING
async def test_do_restore_full(coresys: CoreSys, full_backup_mock, install_addon_ssh):
async def test_do_restore_full(
coresys: CoreSys, supervisor_internet, full_backup_mock, install_addon_ssh
):
"""Test restoring full Backup."""
await coresys.core.set_state(CoreState.RUNNING)
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
@ -247,7 +249,7 @@ async def test_do_restore_full(coresys: CoreSys, full_backup_mock, install_addon
async def test_do_restore_full_different_addon(
coresys: CoreSys, full_backup_mock, install_addon_ssh
coresys: CoreSys, supervisor_internet, full_backup_mock, install_addon_ssh
):
"""Test restoring full Backup with different addons than installed."""
await coresys.core.set_state(CoreState.RUNNING)
@ -279,7 +281,7 @@ async def test_do_restore_full_different_addon(
async def test_do_restore_partial_minimal(
coresys: CoreSys, partial_backup_mock, install_addon_ssh
coresys: CoreSys, supervisor_internet, partial_backup_mock, install_addon_ssh
):
"""Test restoring partial Backup minimal."""
await coresys.core.set_state(CoreState.RUNNING)
@ -303,7 +305,9 @@ async def test_do_restore_partial_minimal(
assert coresys.core.state == CoreState.RUNNING
async def test_do_restore_partial_maximal(coresys: CoreSys, partial_backup_mock):
async def test_do_restore_partial_maximal(
coresys: CoreSys, supervisor_internet, partial_backup_mock
):
"""Test restoring partial Backup minimal."""
await coresys.core.set_state(CoreState.RUNNING)
coresys.hardware.disk.get_disk_free_space = lambda x: 5000
@ -333,7 +337,10 @@ async def test_do_restore_partial_maximal(coresys: CoreSys, partial_backup_mock)
async def test_fail_invalid_full_backup(
coresys: CoreSys, full_backup_mock: MagicMock, partial_backup_mock: MagicMock
coresys: CoreSys,
supervisor_internet,
full_backup_mock: MagicMock,
partial_backup_mock: MagicMock,
):
"""Test restore fails with invalid backup."""
await coresys.core.set_state(CoreState.RUNNING)
@ -365,7 +372,7 @@ async def test_fail_invalid_full_backup(
async def test_fail_invalid_partial_backup(
coresys: CoreSys, partial_backup_mock: MagicMock
coresys: CoreSys, supervisor_internet, partial_backup_mock: MagicMock
):
"""Test restore fails with invalid backup."""
await coresys.core.set_state(CoreState.RUNNING)
@ -415,7 +422,10 @@ async def test_backup_error(
async def test_restore_error(
coresys: CoreSys, full_backup_mock: MagicMock, capture_exception: Mock
coresys: CoreSys,
supervisor_internet,
full_backup_mock: MagicMock,
capture_exception: Mock,
):
"""Test restoring full Backup with errors."""
await coresys.core.set_state(CoreState.RUNNING)
@ -437,6 +447,7 @@ async def test_restore_error(
async def test_backup_media_with_mounts(
coresys: CoreSys,
supervisor_internet,
all_dbus_services: dict[str, DBusServiceMock],
tmp_supervisor_data,
path_extern,
@ -499,6 +510,7 @@ async def test_backup_media_with_mounts(
async def test_backup_media_with_mounts_retains_files(
coresys: CoreSys,
supervisor_internet,
all_dbus_services: dict[str, DBusServiceMock],
tmp_supervisor_data,
path_extern,
@ -553,6 +565,7 @@ async def test_backup_media_with_mounts_retains_files(
async def test_backup_share_with_mounts(
coresys: CoreSys,
supervisor_internet,
all_dbus_services: dict[str, DBusServiceMock],
tmp_supervisor_data,
path_extern,
@ -622,6 +635,7 @@ async def test_backup_share_with_mounts(
async def test_full_backup_to_mount(
coresys: CoreSys,
supervisor_internet,
tmp_supervisor_data,
path_extern,
mount_propagation,
@ -668,6 +682,7 @@ async def test_full_backup_to_mount(
async def test_partial_backup_to_mount(
coresys: CoreSys,
supervisor_internet,
tmp_supervisor_data,
path_extern,
mount_propagation,
@ -985,6 +1000,7 @@ async def test_backup_with_healthcheck(
async def test_restore_with_healthcheck(
coresys: CoreSys,
supervisor_internet,
install_addon_ssh: Addon,
container: MagicMock,
tmp_supervisor_data,
@ -1185,6 +1201,7 @@ async def test_backup_progress(
async def test_restore_progress(
coresys: CoreSys,
supervisor_internet,
install_addon_ssh: Addon,
container: MagicMock,
ha_ws_client: AsyncMock,
@ -1483,6 +1500,7 @@ async def test_cannot_manually_thaw_normal_freeze(coresys: CoreSys):
async def test_restore_only_reloads_ingress_on_change(
coresys: CoreSys,
supervisor_internet,
install_addon_ssh: Addon,
tmp_supervisor_data,
path_extern,
@ -1543,6 +1561,7 @@ async def test_restore_only_reloads_ingress_on_change(
async def test_restore_new_addon(
coresys: CoreSys,
supervisor_internet,
install_addon_example: Addon,
container: MagicMock,
tmp_supervisor_data,
@ -1574,6 +1593,7 @@ async def test_restore_new_addon(
async def test_restore_preserves_data_config(
coresys: CoreSys,
supervisor_internet,
install_addon_example: Addon,
container: MagicMock,
tmp_supervisor_data,
@ -1819,7 +1839,11 @@ async def test_reload_error(
async def test_monitoring_after_full_restore(
coresys: CoreSys, full_backup_mock, install_addon_ssh, container
coresys: CoreSys,
supervisor_internet,
full_backup_mock,
install_addon_ssh,
container,
):
"""Test monitoring of addon state still works after full restore."""
await coresys.core.set_state(CoreState.RUNNING)
@ -1840,7 +1864,11 @@ async def test_monitoring_after_full_restore(
async def test_monitoring_after_partial_restore(
coresys: CoreSys, partial_backup_mock, install_addon_ssh, container
coresys: CoreSys,
supervisor_internet,
partial_backup_mock,
install_addon_ssh,
container,
):
"""Test monitoring of addon state still works after full restore."""
await coresys.core.set_state(CoreState.RUNNING)
@ -2040,7 +2068,9 @@ async def test_backup_remove_one_location_of_multiple(coresys: CoreSys):
@pytest.mark.usefixtures("tmp_supervisor_data")
async def test_addon_backup_excludes(coresys: CoreSys, install_addon_example: Addon):
async def test_addon_backup_excludes(
coresys: CoreSys, supervisor_internet, install_addon_example: Addon
):
"""Test backup excludes option for addons."""
await coresys.core.set_state(CoreState.RUNNING)
coresys.hardware.disk.get_disk_free_space = lambda x: 5000

View File

@ -58,7 +58,7 @@ async def test_check(coresys: CoreSys):
assert coresys.resolution.suggestions[-1].reference == addon.slug
async def test_approve(coresys: CoreSys):
async def test_approve(coresys: CoreSys, supervisor_internet):
"""Test check."""
addon_pwned = CheckAddonPwned(coresys)
await coresys.core.set_state(CoreState.RUNNING)

View File

@ -62,7 +62,7 @@ async def test_check(coresys: CoreSys, dns_query: AsyncMock, capture_exception:
capture_exception.assert_called_once_with(err)
async def test_approve(coresys: CoreSys, dns_query: AsyncMock):
async def test_approve(coresys: CoreSys, supervisor_internet, dns_query: AsyncMock):
"""Test approve existing DNS Server failure issues."""
dns_server = CheckDNSServer(coresys)
await coresys.core.set_state(CoreState.RUNNING)

View File

@ -68,7 +68,7 @@ async def test_check(coresys: CoreSys, dns_query: AsyncMock, capture_exception:
capture_exception.assert_called_once_with(err)
async def test_approve(coresys: CoreSys, dns_query: AsyncMock):
async def test_approve(coresys: CoreSys, supervisor_internet, dns_query: AsyncMock):
"""Test approve existing DNS Server IPv6 error issues."""
dns_server_ipv6 = CheckDNSServerIPv6(coresys)
await coresys.core.set_state(CoreState.RUNNING)

View File

@ -9,7 +9,7 @@ from supervisor.resolution.data import Issue, Suggestion
from supervisor.resolution.fixups.store_execute_reload import FixupStoreExecuteReload
async def test_fixup(coresys: CoreSys):
async def test_fixup(coresys: CoreSys, supervisor_internet):
"""Test fixup."""
store_execute_reload = FixupStoreExecuteReload(coresys)

View File

@ -11,7 +11,7 @@ from supervisor.resolution.data import Issue, Suggestion
from supervisor.resolution.fixups.store_execute_reset import FixupStoreExecuteReset
async def test_fixup(coresys: CoreSys, tmp_path):
async def test_fixup(coresys: CoreSys, supervisor_internet, tmp_path):
"""Test fixup."""
store_execute_reset = FixupStoreExecuteReset(coresys)
test_repo = Path(tmp_path, "test_repo")

View File

@ -203,7 +203,9 @@ def _supervisor_event_message(event: str, data: dict[str, Any]) -> dict[str, Any
}
async def test_events_on_issue_changes(coresys: CoreSys, ha_ws_client: AsyncMock):
async def test_events_on_issue_changes(
coresys: CoreSys, supervisor_internet, ha_ws_client: AsyncMock
):
"""Test events fired when an issue changes."""
# Creating an issue with a suggestion should fire exactly one issue changed event
assert coresys.resolution.issues == []

View File

@ -20,6 +20,12 @@ from supervisor.store.addon import AddonStore
from supervisor.store.repository import Repository
@pytest.fixture(autouse=True)
def _auto_supervisor_internet(supervisor_internet):
# Use the supervisor_internet fixture to ensure that all tests has internet access
pass
@pytest.mark.parametrize("use_update", [True, False])
async def test_add_valid_repository(
coresys: CoreSys, store_manager: StoreManager, use_update: bool

View File

@ -228,7 +228,7 @@ async def test_install_unavailable_addon(
@pytest.mark.usefixtures("tmp_supervisor_data")
async def test_reload(coresys: CoreSys):
async def test_reload(coresys: CoreSys, supervisor_internet):
"""Test store reload."""
await coresys.store.load()
assert len(coresys.store.all) == 5