From c3e733c0aa20085f698a221def7678196b2c8fe9 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 8 Feb 2023 10:51:25 +0100 Subject: [PATCH] Replace global test markers with fixtures in Devolo home control tests (#87676) --- .../devolo_home_control/conftest.py | 29 ++++++++++--------- .../devolo_home_control/test_config_flow.py | 6 ++-- .../devolo_home_control/test_init.py | 4 +-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/components/devolo_home_control/conftest.py b/tests/components/devolo_home_control/conftest.py index 65e8b9b1c64..786652c7753 100644 --- a/tests/components/devolo_home_control/conftest.py +++ b/tests/components/devolo_home_control/conftest.py @@ -1,31 +1,34 @@ """Fixtures for tests.""" +from collections.abc import Generator from unittest.mock import patch import pytest -def pytest_configure(config): - """Define custom markers.""" - config.addinivalue_line( - "markers", - "credentials_invalid: Treat credentials as invalid.", - ) - config.addinivalue_line( - "markers", - "maintenance: Set maintenance mode to on.", - ) +@pytest.fixture +def credentials_valid() -> bool: + """Mark test as credentials invalid.""" + return True + + +@pytest.fixture +def maintenance() -> bool: + """Mark test as maintenance mode on.""" + return False @pytest.fixture(autouse=True) -def patch_mydevolo(request): +def patch_mydevolo( + credentials_valid: bool, maintenance: bool +) -> Generator[None, None, None]: """Fixture to patch mydevolo into a desired state.""" with patch( "homeassistant.components.devolo_home_control.Mydevolo.credentials_valid", - return_value=not bool(request.node.get_closest_marker("credentials_invalid")), + return_value=credentials_valid, ), patch( "homeassistant.components.devolo_home_control.Mydevolo.maintenance", - return_value=bool(request.node.get_closest_marker("maintenance")), + return_value=maintenance, ), patch( "homeassistant.components.devolo_home_control.Mydevolo.get_gateway_ids", return_value=["1400000000000001", "1400000000000002"], diff --git a/tests/components/devolo_home_control/test_config_flow.py b/tests/components/devolo_home_control/test_config_flow.py index 4f7140b7980..1c04f0c83a6 100644 --- a/tests/components/devolo_home_control/test_config_flow.py +++ b/tests/components/devolo_home_control/test_config_flow.py @@ -30,7 +30,7 @@ async def test_form(hass: HomeAssistant) -> None: await _setup(hass, result) -@pytest.mark.credentials_invalid +@pytest.mark.parametrize("credentials_valid", [False]) async def test_form_invalid_credentials_user(hass: HomeAssistant) -> None: """Test if we get the error message on invalid credentials.""" @@ -116,7 +116,7 @@ async def test_form_zeroconf(hass: HomeAssistant) -> None: await _setup(hass, result) -@pytest.mark.credentials_invalid +@pytest.mark.parametrize("credentials_valid", [False]) async def test_form_invalid_credentials_zeroconf(hass: HomeAssistant) -> None: """Test if we get the error message on invalid credentials.""" @@ -195,7 +195,7 @@ async def test_form_reauth(hass: HomeAssistant) -> None: assert len(mock_setup_entry.mock_calls) == 1 -@pytest.mark.credentials_invalid +@pytest.mark.parametrize("credentials_valid", [False]) async def test_form_invalid_credentials_reauth(hass: HomeAssistant) -> None: """Test if we get the error message on invalid credentials.""" mock_config = MockConfigEntry(domain=DOMAIN, unique_id="123456", data={}) diff --git a/tests/components/devolo_home_control/test_init.py b/tests/components/devolo_home_control/test_init.py index f12ea9486b4..08b8ec29d9f 100644 --- a/tests/components/devolo_home_control/test_init.py +++ b/tests/components/devolo_home_control/test_init.py @@ -25,7 +25,7 @@ async def test_setup_entry(hass: HomeAssistant, mock_zeroconf): assert entry.state is ConfigEntryState.LOADED -@pytest.mark.credentials_invalid +@pytest.mark.parametrize("credentials_valid", [False]) async def test_setup_entry_credentials_invalid(hass: HomeAssistant): """Test setup entry fails if credentials are invalid.""" entry = configure_integration(hass) @@ -33,7 +33,7 @@ async def test_setup_entry_credentials_invalid(hass: HomeAssistant): assert entry.state is ConfigEntryState.SETUP_ERROR -@pytest.mark.maintenance +@pytest.mark.parametrize("maintenance", [True]) async def test_setup_entry_maintenance(hass: HomeAssistant): """Test setup entry fails if mydevolo is in maintenance mode.""" entry = configure_integration(hass)