mirror of
https://github.com/home-assistant/operating-system.git
synced 2025-04-21 15:47:15 +00:00

* Improve handling of timeouts in tests Make timeout handling in tests more transparent. Added a custom shell driver that allows to define global timeout for commands in the config file, and replaced for/sleep constructs with infinite loops that will be eventually terminated by pytest-timeout plugin. Current timeouts taken from last runs on Github CI with some extra headroom. * test_supervisor_is_updated shouldn't be skipped if no update was needed * Allow more time for system startup * Allow even more time for system startup
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
import json
|
|
import logging
|
|
import os
|
|
|
|
from labgrid.driver import ShellDriver
|
|
import pytest
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope="module")
|
|
def restart_qemu(strategy):
|
|
"""Use fresh QEMU instance for each module."""
|
|
if strategy.status.name == "shell":
|
|
logger.info("Restarting QEMU before %s module tests.", strategy.target.name)
|
|
strategy.transition("off")
|
|
strategy.transition("shell")
|
|
|
|
|
|
@pytest.hookimpl
|
|
def pytest_runtest_setup(item):
|
|
log_dir = item.config.option.lg_log
|
|
|
|
if not log_dir:
|
|
return
|
|
|
|
logging_plugin = item.config.pluginmanager.get_plugin("logging-plugin")
|
|
log_name = item.nodeid.replace(".py::", "/")
|
|
logging_plugin.set_log_path(os.path.join(log_dir, f"{log_name}.log"))
|
|
|
|
|
|
@pytest.fixture
|
|
def shell(target, strategy) -> ShellDriver:
|
|
"""Fixture for accessing shell."""
|
|
strategy.transition("shell")
|
|
shell = target.get_driver("ShellDriver")
|
|
return shell
|
|
|
|
|
|
@pytest.fixture
|
|
def shell_json(target, strategy) -> callable:
|
|
"""Fixture for running CLI commands returning JSON string as output."""
|
|
strategy.transition("shell")
|
|
shell = target.get_driver("ShellDriver")
|
|
|
|
def get_json_response(command, *, timeout=None) -> dict:
|
|
return json.loads("\n".join(shell.run_check(command, timeout=timeout)))
|
|
|
|
return get_json_response
|