From 75e355faf9e6558ddb53c374a5680e8223718646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Tue, 30 Jul 2024 08:36:59 +0200 Subject: [PATCH] pytest: changes fixture scopes --- tests/client/test_client.py | 2 +- tests/components/test_device_connection.py | 2 +- tests/data_service/test_data_service_cache.py | 2 +- tests/data_service/test_task_manager.py | 8 ++++---- tests/server/web_server/api/v1/test_endpoints.py | 6 +++--- tests/utils/serialization/test_serializer.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index fa4ef98..7a66bb2 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -7,7 +7,7 @@ import pytest from pydase.client.proxy_loader import ProxyAttributeError -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def pydase_client() -> Generator[pydase.Client, None, Any]: class SubService(pydase.DataService): name = "SubService" diff --git a/tests/components/test_device_connection.py b/tests/components/test_device_connection.py index 8c5c9d5..3f5e92c 100644 --- a/tests/components/test_device_connection.py +++ b/tests/components/test_device_connection.py @@ -6,7 +6,7 @@ import pytest from pytest import LogCaptureFixture -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_reconnection(caplog: LogCaptureFixture) -> None: class MyService(pydase.components.device_connection.DeviceConnection): def __init__( diff --git a/tests/data_service/test_data_service_cache.py b/tests/data_service/test_data_service_cache.py index e21e64e..8e85403 100644 --- a/tests/data_service/test_data_service_cache.py +++ b/tests/data_service/test_data_service_cache.py @@ -35,7 +35,7 @@ def test_nested_attributes_cache_callback() -> None: ) -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_task_status_update() -> None: class ServiceClass(pydase.DataService): name = "World" diff --git a/tests/data_service/test_task_manager.py b/tests/data_service/test_task_manager.py index bb1619b..7a1a682 100644 --- a/tests/data_service/test_task_manager.py +++ b/tests/data_service/test_task_manager.py @@ -10,7 +10,7 @@ from pytest import LogCaptureFixture logger = logging.getLogger("pydase") -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: class MyService(pydase.DataService): def __init__(self) -> None: @@ -36,7 +36,7 @@ async def test_autostart_task_callback(caplog: LogCaptureFixture) -> None: assert "'my_other_task' changed to 'TaskStatus.RUNNING'" in caplog.text -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_DataService_subclass_autostart_task_callback( caplog: LogCaptureFixture, ) -> None: @@ -66,7 +66,7 @@ async def test_DataService_subclass_autostart_task_callback( assert "'sub_service.my_other_task' changed to 'TaskStatus.RUNNING'" in caplog.text -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_DataService_subclass_list_autostart_task_callback( caplog: LogCaptureFixture, ) -> None: @@ -108,7 +108,7 @@ async def test_DataService_subclass_list_autostart_task_callback( ) -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="function") async def test_start_and_stop_task_methods(caplog: LogCaptureFixture) -> None: class MyService(pydase.DataService): def __init__(self) -> None: diff --git a/tests/server/web_server/api/v1/test_endpoints.py b/tests/server/web_server/api/v1/test_endpoints.py index dfedff1..ed6f2ef 100644 --- a/tests/server/web_server/api/v1/test_endpoints.py +++ b/tests/server/web_server/api/v1/test_endpoints.py @@ -8,7 +8,7 @@ import pydase import pytest -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def pydase_server() -> Generator[None, None, None]: class SubService(pydase.DataService): name = "SubService" @@ -103,7 +103,7 @@ def pydase_server() -> Generator[None, None, None]: ), ], ) -@pytest.mark.asyncio +@pytest.mark.asyncio(scope="module") async def test_get_value( access_path: str, expected: dict[str, Any], @@ -171,7 +171,7 @@ async def test_get_value( ), ], ) -@pytest.mark.asyncio +@pytest.mark.asyncio(scope="module") async def test_update_value( access_path: str, new_value: dict[str, Any], diff --git a/tests/utils/serialization/test_serializer.py b/tests/utils/serialization/test_serializer.py index 0dc872d..90612af 100644 --- a/tests/utils/serialization/test_serializer.py +++ b/tests/utils/serialization/test_serializer.py @@ -207,7 +207,7 @@ def test_ColouredEnum_serialize() -> None: } -@pytest.mark.asyncio(scope="session") +@pytest.mark.asyncio(scope="module") async def test_method_serialization() -> None: class ClassWithMethod(pydase.DataService): def some_method(self) -> str: