From 928aff342f16a1b3f5c642c9cd921b522772cba4 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 15 Nov 2023 10:45:36 +0100 Subject: [PATCH] Address pytest warnings (#4695) --- pytest.ini | 4 +++ tests/api/middleware/test_security.py | 5 ++-- tests/api/test_addons.py | 8 ++--- tests/api/test_audio.py | 8 ++--- tests/api/test_dns.py | 8 ++--- tests/api/test_homeassistant.py | 8 ++--- tests/api/test_multicast.py | 8 ++--- tests/api/test_supervisor.py | 8 ++--- tests/dbus/test_interface.py | 1 + tests/jobs/test_job_decorator.py | 42 +++++++++++++++------------ tests/utils/test_dbus.py | 1 + 11 files changed, 56 insertions(+), 45 deletions(-) diff --git a/pytest.ini b/pytest.ini index 2f4c80e30..3a7f04a0b 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,6 @@ [pytest] asyncio_mode = auto +filterwarnings = + error + ignore:pkg_resources is deprecated as an API:DeprecationWarning:dirhash + ignore::pytest.PytestUnraisableExceptionWarning diff --git a/tests/api/middleware/test_security.py b/tests/api/middleware/test_security.py index 03df09877..fbdb3ac72 100644 --- a/tests/api/middleware/test_security.py +++ b/tests/api/middleware/test_security.py @@ -1,4 +1,5 @@ """Test API security layer.""" +import asyncio from http import HTTPStatus from unittest.mock import patch @@ -109,7 +110,7 @@ async def test_bad_requests( fail_on_query_string, api_system, caplog: pytest.LogCaptureFixture, - loop, + event_loop: asyncio.BaseEventLoop, ) -> None: """Test request paths that should be filtered.""" @@ -121,7 +122,7 @@ async def test_bad_requests( man_params = "" http = urllib3.PoolManager() - resp = await loop.run_in_executor( + resp = await event_loop.run_in_executor( None, http.request, "GET", diff --git a/tests/api/test_addons.py b/tests/api/test_addons.py index 2875ab38b..06849a5a8 100644 --- a/tests/api/test_addons.py +++ b/tests/api/test_addons.py @@ -73,10 +73,10 @@ async def test_api_addon_logs( resp = await api_client.get("/addons/local_ssh/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/api/test_audio.py b/tests/api/test_audio.py index 9794c9f62..9f7d31264 100644 --- a/tests/api/test_audio.py +++ b/tests/api/test_audio.py @@ -10,8 +10,8 @@ async def test_api_audio_logs(api_client: TestClient, docker_logs: MagicMock): resp = await api_client.get("/audio/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/api/test_dns.py b/tests/api/test_dns.py index c21f8dc30..4c6c3b034 100644 --- a/tests/api/test_dns.py +++ b/tests/api/test_dns.py @@ -69,8 +69,8 @@ async def test_api_dns_logs(api_client: TestClient, docker_logs: MagicMock): resp = await api_client.get("/dns/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/api/test_homeassistant.py b/tests/api/test_homeassistant.py index 12e835a6d..15ed7cbbe 100644 --- a/tests/api/test_homeassistant.py +++ b/tests/api/test_homeassistant.py @@ -19,10 +19,10 @@ async def test_api_core_logs( resp = await api_client.get(f"/{'homeassistant' if legacy_route else 'core'}/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/api/test_multicast.py b/tests/api/test_multicast.py index 45827031b..5ef1d8cf1 100644 --- a/tests/api/test_multicast.py +++ b/tests/api/test_multicast.py @@ -10,8 +10,8 @@ async def test_api_multicast_logs(api_client: TestClient, docker_logs: MagicMock resp = await api_client.get("/multicast/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/api/test_supervisor.py b/tests/api/test_supervisor.py index 81dcc6eba..c28b49b62 100644 --- a/tests/api/test_supervisor.py +++ b/tests/api/test_supervisor.py @@ -155,10 +155,10 @@ async def test_api_supervisor_logs(api_client: TestClient, docker_logs: MagicMoc resp = await api_client.get("/supervisor/logs") assert resp.status == 200 assert resp.content_type == "application/octet-stream" - content = await resp.text() - assert content.split("\n")[0:2] == [ - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", - "\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", + content = await resp.read() + assert content.split(b"\n")[0:2] == [ + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os\x1b[0m", + b"\x1b[36m22-10-11 14:04:23 DEBUG (MainThread) [supervisor.utils.dbus] D-Bus call - org.freedesktop.DBus.Properties.call_get_all on /io/hass/os/AppArmor\x1b[0m", ] diff --git a/tests/dbus/test_interface.py b/tests/dbus/test_interface.py index 590b8595a..cc5edda74 100644 --- a/tests/dbus/test_interface.py +++ b/tests/dbus/test_interface.py @@ -18,6 +18,7 @@ from tests.dbus_service_mocks.base import DBusServiceMock class TestInterface(DBusServiceMock): """Test interface.""" + __test__ = False interface = "service.test.TestInterface" def __init__(self, object_path: str = "/service/test/TestInterface"): diff --git a/tests/jobs/test_job_decorator.py b/tests/jobs/test_job_decorator.py index 85382d245..85d09c74b 100644 --- a/tests/jobs/test_job_decorator.py +++ b/tests/jobs/test_job_decorator.py @@ -275,7 +275,7 @@ async def test_exception_conditions(coresys: CoreSys): async def test_execution_limit_single_wait( - coresys: CoreSys, loop: asyncio.BaseEventLoop + coresys: CoreSys, event_loop: asyncio.BaseEventLoop ): """Test the single wait job execution limit.""" @@ -303,7 +303,7 @@ async def test_execution_limit_single_wait( async def test_execution_limit_throttle_wait( - coresys: CoreSys, loop: asyncio.BaseEventLoop + coresys: CoreSys, event_loop: asyncio.BaseEventLoop ): """Test the throttle wait job execution limit.""" @@ -339,7 +339,7 @@ async def test_execution_limit_throttle_wait( @pytest.mark.parametrize("error", [None, PluginJobError]) async def test_execution_limit_throttle_rate_limit( - coresys: CoreSys, loop: asyncio.BaseEventLoop, error: JobException | None + coresys: CoreSys, event_loop: asyncio.BaseEventLoop, error: JobException | None ): """Test the throttle wait job execution limit.""" @@ -379,7 +379,9 @@ async def test_execution_limit_throttle_rate_limit( assert test.call == 3 -async def test_execution_limit_throttle(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_execution_limit_throttle( + coresys: CoreSys, event_loop: asyncio.BaseEventLoop +): """Test the ignore conditions decorator.""" class TestClass: @@ -412,7 +414,9 @@ async def test_execution_limit_throttle(coresys: CoreSys, loop: asyncio.BaseEven assert test.call == 1 -async def test_execution_limit_once(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_execution_limit_once( + coresys: CoreSys, event_loop: asyncio.BaseEventLoop +): """Test the ignore conditions decorator.""" class TestClass: @@ -435,7 +439,7 @@ async def test_execution_limit_once(coresys: CoreSys, loop: asyncio.BaseEventLoo await asyncio.sleep(sleep) test = TestClass(coresys) - run_task = loop.create_task(test.execute(0.3)) + run_task = event_loop.create_task(test.execute(0.3)) await asyncio.sleep(0.1) with pytest.raises(JobException): @@ -591,7 +595,7 @@ async def test_host_network(coresys: CoreSys): assert await test.execute() -async def test_job_group_once(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_job_group_once(coresys: CoreSys, event_loop: asyncio.BaseEventLoop): """Test job group once execution limitation.""" class TestClass(JobGroup): @@ -640,7 +644,7 @@ async def test_job_group_once(coresys: CoreSys, loop: asyncio.BaseEventLoop): return True test = TestClass(coresys) - run_task = loop.create_task(test.execute()) + run_task = event_loop.create_task(test.execute()) await asyncio.sleep(0) # All methods with group limits should be locked @@ -660,7 +664,7 @@ async def test_job_group_once(coresys: CoreSys, loop: asyncio.BaseEventLoop): assert await run_task -async def test_job_group_wait(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_job_group_wait(coresys: CoreSys, event_loop: asyncio.BaseEventLoop): """Test job group wait execution limitation.""" class TestClass(JobGroup): @@ -702,11 +706,11 @@ async def test_job_group_wait(coresys: CoreSys, loop: asyncio.BaseEventLoop): self.other_count += 1 test = TestClass(coresys) - run_task = loop.create_task(test.execute()) + run_task = event_loop.create_task(test.execute()) await asyncio.sleep(0) - repeat_task = loop.create_task(test.execute()) - other_task = loop.create_task(test.separate_execute()) + repeat_task = event_loop.create_task(test.execute()) + other_task = event_loop.create_task(test.separate_execute()) await asyncio.sleep(0) assert test.execute_count == 1 @@ -721,7 +725,7 @@ async def test_job_group_wait(coresys: CoreSys, loop: asyncio.BaseEventLoop): assert test.other_count == 1 -async def test_job_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_job_cleanup(coresys: CoreSys, event_loop: asyncio.BaseEventLoop): """Test job is cleaned up.""" class TestClass: @@ -741,7 +745,7 @@ async def test_job_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): return True test = TestClass(coresys) - run_task = loop.create_task(test.execute()) + run_task = event_loop.create_task(test.execute()) await asyncio.sleep(0) assert coresys.jobs.jobs == [test.job] @@ -754,7 +758,7 @@ async def test_job_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): assert test.job.done -async def test_job_skip_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): +async def test_job_skip_cleanup(coresys: CoreSys, event_loop: asyncio.BaseEventLoop): """Test job is left in job manager when cleanup is false.""" class TestClass: @@ -778,7 +782,7 @@ async def test_job_skip_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): return True test = TestClass(coresys) - run_task = loop.create_task(test.execute()) + run_task = event_loop.create_task(test.execute()) await asyncio.sleep(0) assert coresys.jobs.jobs == [test.job] @@ -792,7 +796,7 @@ async def test_job_skip_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop): async def test_execution_limit_group_throttle( - coresys: CoreSys, loop: asyncio.BaseEventLoop + coresys: CoreSys, event_loop: asyncio.BaseEventLoop ): """Test the group throttle execution limit.""" @@ -841,7 +845,7 @@ async def test_execution_limit_group_throttle( async def test_execution_limit_group_throttle_wait( - coresys: CoreSys, loop: asyncio.BaseEventLoop + coresys: CoreSys, event_loop: asyncio.BaseEventLoop ): """Test the group throttle wait job execution limit.""" @@ -893,7 +897,7 @@ async def test_execution_limit_group_throttle_wait( @pytest.mark.parametrize("error", [None, PluginJobError]) async def test_execution_limit_group_throttle_rate_limit( - coresys: CoreSys, loop: asyncio.BaseEventLoop, error: JobException | None + coresys: CoreSys, event_loop: asyncio.BaseEventLoop, error: JobException | None ): """Test the group throttle rate limit job execution limit.""" diff --git a/tests/utils/test_dbus.py b/tests/utils/test_dbus.py index 229594349..d34e536dc 100644 --- a/tests/utils/test_dbus.py +++ b/tests/utils/test_dbus.py @@ -17,6 +17,7 @@ from tests.dbus_service_mocks.base import DBusServiceMock class TestInterface(DBusServiceMock): """Test interface.""" + __test__ = False interface = "service.test.TestInterface" object_path = DBUS_OBJECT_BASE