hass-core/tests/components/devolo_home_control/conftest.py
Guido Schmitz 8065ece0bd
Add first set of tests to devolo Home Control integration (#42527)
* Add first two testcases

* Remove repetition

* Add first two testcases

* Remove repetition

* Add connection error test case

* add test_setup_entry_credentials_valid

* First attempt to use fixtures

* Use markers

* Optimize patch

* Optimize marker use

* Always patch mydevolo

* Add first two testcases

* Remove repetition

* Add first two testcases

* Remove repetition

* Add connection error test case

* add test_setup_entry_credentials_valid

* First attempt to use fixtures

* Use markers

* Optimize patch

* Optimize marker use

* Always patch mydevolo

* Add unload entry test case

* Catch up with reality

* Use unittest patch

* Use core interface to start tests

* Use entry state

* Consistently assert entry state

* Patch class instead of init

Co-authored-by: Markus Bong <2Fake1987@gmail.com>
2021-01-28 17:14:33 +01:00

33 lines
1,011 B
Python

"""Fixtures for tests."""
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(autouse=True)
def patch_mydevolo(request):
"""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")),
), patch(
"homeassistant.components.devolo_home_control.Mydevolo.maintenance",
return_value=bool(request.node.get_closest_marker("maintenance")),
), patch(
"homeassistant.components.devolo_home_control.Mydevolo.get_gateway_ids",
return_value=["1400000000000001", "1400000000000002"],
):
yield