Address pytest warnings (#4695)

This commit is contained in:
Stefan Agner 2023-11-15 10:45:36 +01:00 committed by GitHub
parent 60a97235df
commit 928aff342f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 45 deletions

View File

@ -1,2 +1,6 @@
[pytest] [pytest]
asyncio_mode = auto asyncio_mode = auto
filterwarnings =
error
ignore:pkg_resources is deprecated as an API:DeprecationWarning:dirhash
ignore::pytest.PytestUnraisableExceptionWarning

View File

@ -1,4 +1,5 @@
"""Test API security layer.""" """Test API security layer."""
import asyncio
from http import HTTPStatus from http import HTTPStatus
from unittest.mock import patch from unittest.mock import patch
@ -109,7 +110,7 @@ async def test_bad_requests(
fail_on_query_string, fail_on_query_string,
api_system, api_system,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
loop, event_loop: asyncio.BaseEventLoop,
) -> None: ) -> None:
"""Test request paths that should be filtered.""" """Test request paths that should be filtered."""
@ -121,7 +122,7 @@ async def test_bad_requests(
man_params = "" man_params = ""
http = urllib3.PoolManager() http = urllib3.PoolManager()
resp = await loop.run_in_executor( resp = await event_loop.run_in_executor(
None, None,
http.request, http.request,
"GET", "GET",

View File

@ -73,10 +73,10 @@ async def test_api_addon_logs(
resp = await api_client.get("/addons/local_ssh/logs") resp = await api_client.get("/addons/local_ssh/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -10,8 +10,8 @@ async def test_api_audio_logs(api_client: TestClient, docker_logs: MagicMock):
resp = await api_client.get("/audio/logs") resp = await api_client.get("/audio/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -69,8 +69,8 @@ async def test_api_dns_logs(api_client: TestClient, docker_logs: MagicMock):
resp = await api_client.get("/dns/logs") resp = await api_client.get("/dns/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -19,10 +19,10 @@ async def test_api_core_logs(
resp = await api_client.get(f"/{'homeassistant' if legacy_route else 'core'}/logs") resp = await api_client.get(f"/{'homeassistant' if legacy_route else 'core'}/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -10,8 +10,8 @@ async def test_api_multicast_logs(api_client: TestClient, docker_logs: MagicMock
resp = await api_client.get("/multicast/logs") resp = await api_client.get("/multicast/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -155,10 +155,10 @@ async def test_api_supervisor_logs(api_client: TestClient, docker_logs: MagicMoc
resp = await api_client.get("/supervisor/logs") resp = await api_client.get("/supervisor/logs")
assert resp.status == 200 assert resp.status == 200
assert resp.content_type == "application/octet-stream" assert resp.content_type == "application/octet-stream"
content = await resp.text() content = await resp.read()
assert content.split("\n")[0:2] == [ assert content.split(b"\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", 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",
"\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", 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",
] ]

View File

@ -18,6 +18,7 @@ from tests.dbus_service_mocks.base import DBusServiceMock
class TestInterface(DBusServiceMock): class TestInterface(DBusServiceMock):
"""Test interface.""" """Test interface."""
__test__ = False
interface = "service.test.TestInterface" interface = "service.test.TestInterface"
def __init__(self, object_path: str = "/service/test/TestInterface"): def __init__(self, object_path: str = "/service/test/TestInterface"):

View File

@ -275,7 +275,7 @@ async def test_exception_conditions(coresys: CoreSys):
async def test_execution_limit_single_wait( 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.""" """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( 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.""" """Test the throttle wait job execution limit."""
@ -339,7 +339,7 @@ async def test_execution_limit_throttle_wait(
@pytest.mark.parametrize("error", [None, PluginJobError]) @pytest.mark.parametrize("error", [None, PluginJobError])
async def test_execution_limit_throttle_rate_limit( 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.""" """Test the throttle wait job execution limit."""
@ -379,7 +379,9 @@ async def test_execution_limit_throttle_rate_limit(
assert test.call == 3 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.""" """Test the ignore conditions decorator."""
class TestClass: class TestClass:
@ -412,7 +414,9 @@ async def test_execution_limit_throttle(coresys: CoreSys, loop: asyncio.BaseEven
assert test.call == 1 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.""" """Test the ignore conditions decorator."""
class TestClass: class TestClass:
@ -435,7 +439,7 @@ async def test_execution_limit_once(coresys: CoreSys, loop: asyncio.BaseEventLoo
await asyncio.sleep(sleep) await asyncio.sleep(sleep)
test = TestClass(coresys) 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) await asyncio.sleep(0.1)
with pytest.raises(JobException): with pytest.raises(JobException):
@ -591,7 +595,7 @@ async def test_host_network(coresys: CoreSys):
assert await test.execute() 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.""" """Test job group once execution limitation."""
class TestClass(JobGroup): class TestClass(JobGroup):
@ -640,7 +644,7 @@ async def test_job_group_once(coresys: CoreSys, loop: asyncio.BaseEventLoop):
return True return True
test = TestClass(coresys) test = TestClass(coresys)
run_task = loop.create_task(test.execute()) run_task = event_loop.create_task(test.execute())
await asyncio.sleep(0) await asyncio.sleep(0)
# All methods with group limits should be locked # 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 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.""" """Test job group wait execution limitation."""
class TestClass(JobGroup): class TestClass(JobGroup):
@ -702,11 +706,11 @@ async def test_job_group_wait(coresys: CoreSys, loop: asyncio.BaseEventLoop):
self.other_count += 1 self.other_count += 1
test = TestClass(coresys) test = TestClass(coresys)
run_task = loop.create_task(test.execute()) run_task = event_loop.create_task(test.execute())
await asyncio.sleep(0) await asyncio.sleep(0)
repeat_task = loop.create_task(test.execute()) repeat_task = event_loop.create_task(test.execute())
other_task = loop.create_task(test.separate_execute()) other_task = event_loop.create_task(test.separate_execute())
await asyncio.sleep(0) await asyncio.sleep(0)
assert test.execute_count == 1 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 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.""" """Test job is cleaned up."""
class TestClass: class TestClass:
@ -741,7 +745,7 @@ async def test_job_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop):
return True return True
test = TestClass(coresys) test = TestClass(coresys)
run_task = loop.create_task(test.execute()) run_task = event_loop.create_task(test.execute())
await asyncio.sleep(0) await asyncio.sleep(0)
assert coresys.jobs.jobs == [test.job] assert coresys.jobs.jobs == [test.job]
@ -754,7 +758,7 @@ async def test_job_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop):
assert test.job.done 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.""" """Test job is left in job manager when cleanup is false."""
class TestClass: class TestClass:
@ -778,7 +782,7 @@ async def test_job_skip_cleanup(coresys: CoreSys, loop: asyncio.BaseEventLoop):
return True return True
test = TestClass(coresys) test = TestClass(coresys)
run_task = loop.create_task(test.execute()) run_task = event_loop.create_task(test.execute())
await asyncio.sleep(0) await asyncio.sleep(0)
assert coresys.jobs.jobs == [test.job] 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( async def test_execution_limit_group_throttle(
coresys: CoreSys, loop: asyncio.BaseEventLoop coresys: CoreSys, event_loop: asyncio.BaseEventLoop
): ):
"""Test the group throttle execution limit.""" """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( 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.""" """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]) @pytest.mark.parametrize("error", [None, PluginJobError])
async def test_execution_limit_group_throttle_rate_limit( 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.""" """Test the group throttle rate limit job execution limit."""

View File

@ -17,6 +17,7 @@ from tests.dbus_service_mocks.base import DBusServiceMock
class TestInterface(DBusServiceMock): class TestInterface(DBusServiceMock):
"""Test interface.""" """Test interface."""
__test__ = False
interface = "service.test.TestInterface" interface = "service.test.TestInterface"
object_path = DBUS_OBJECT_BASE object_path = DBUS_OBJECT_BASE